如何将一个python脚本的输出作为另一个python脚本的用户输入
我已经编写了一个代码(python 2.7),它进入一个网站,然后从中取出一些数据来显示它的分数。它还定期重复并继续运行,因为分数不断变化。 我还编写了一个代码,用于接收用户输入的消息,并将该消息作为sms发送到我的号码 我想把这两个组合在一起,这样屏幕上打印的分数就可以作为向我发送实时分数的信息输入 代码是 sms.py如何将一个python脚本的输出作为另一个python脚本的用户输入,python,python-2.7,windows-10,Python,Python 2.7,Windows 10,我已经编写了一个代码(python 2.7),它进入一个网站,然后从中取出一些数据来显示它的分数。它还定期重复并继续运行,因为分数不断变化。 我还编写了一个代码,用于接收用户输入的消息,并将该消息作为sms发送到我的号码 我想把这两个组合在一起,这样屏幕上打印的分数就可以作为向我发送实时分数的信息输入 代码是 sms.py import urllib2 import cookielib from getpass import getpass import sys
import urllib2
import cookielib
from getpass import getpass
import sys
import os
from stat import *
import sched, time
import requests
from bs4 import BeautifulSoup
s = sched.scheduler(time.time, time.sleep)
from urllib2 import Request
#from livematch import function
#this sends the desired input message to my number
number = raw_input('enter number you want to message: ')
message = raw_input('enter text: ' )
#this declares my credentials
if __name__ == "__main__":
username = "9876543210"
passwd = "abcdefghij"
message = "+".join(message.split(' '))
#logging into the sms site
url ='http://site24.way2sms.com/Login1.action?'
data = 'username='+username+'&password='+passwd+'&Submit=Sign+in'
#For cookies
cj= cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
#Adding header details
opener.addheaders=[('User-Agent','Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120')]
try:
usock =opener.open(url, data)
except IOError:
print "error"
#return()
jession_id =str(cj).split('~')[1].split(' ')[0]
send_sms_url = 'http://site24.way2sms.com/smstoss.action?'
send_sms_data = 'ssaction=ss&Token='+jession_id+'&mobile='+number+'&message='+message+'&msgLen=136'
opener.addheaders=[('Referer', 'http://site25.way2sms.com/sendSMS?Token='+jession_id)]
try:
sms_sent_page = opener.open(send_sms_url,send_sms_data)
except IOError:
print "error"
#return()
print "success"
#return ()
import sched, time
import requests
from bs4 import BeautifulSoup
s = sched.scheduler(time.time, time.sleep)
from urllib2 import Request
url=raw_input('enter the desired score card url here : ')
req=Request(url)
def do_something(sc) :
#global x
r=requests.get(url)
soup=BeautifulSoup(r.content)
for i in soup.find_all("div",{"id":"innings_1"}):
x=i.text.find('Batsman')
in_1=i.text
print(in_1[0:x])
for i in soup.find_all("div",{"id":"innings_2"}):
x=i.text.find('Batsman')
in_1=i.text
print(in_1[0:x])
for i in soup.find_all("div",{"id":"innings_3"}):
x=i.text.find('Batsman')
in_1=i.text
print(in_1[0:x])
for i in soup.find_all("div",{"id":"innings_4"}):
x=i.text.find('Batsman')
in_1=i.text
print(in_1[0:x])
# do your stuff
#do what ever
s.enter(5, 1, do_something, (sc,))
s.enter(5, 1, do_something, (s,))
s.run()
livematch.py
import urllib2
import cookielib
from getpass import getpass
import sys
import os
from stat import *
import sched, time
import requests
from bs4 import BeautifulSoup
s = sched.scheduler(time.time, time.sleep)
from urllib2 import Request
#from livematch import function
#this sends the desired input message to my number
number = raw_input('enter number you want to message: ')
message = raw_input('enter text: ' )
#this declares my credentials
if __name__ == "__main__":
username = "9876543210"
passwd = "abcdefghij"
message = "+".join(message.split(' '))
#logging into the sms site
url ='http://site24.way2sms.com/Login1.action?'
data = 'username='+username+'&password='+passwd+'&Submit=Sign+in'
#For cookies
cj= cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
#Adding header details
opener.addheaders=[('User-Agent','Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120')]
try:
usock =opener.open(url, data)
except IOError:
print "error"
#return()
jession_id =str(cj).split('~')[1].split(' ')[0]
send_sms_url = 'http://site24.way2sms.com/smstoss.action?'
send_sms_data = 'ssaction=ss&Token='+jession_id+'&mobile='+number+'&message='+message+'&msgLen=136'
opener.addheaders=[('Referer', 'http://site25.way2sms.com/sendSMS?Token='+jession_id)]
try:
sms_sent_page = opener.open(send_sms_url,send_sms_data)
except IOError:
print "error"
#return()
print "success"
#return ()
import sched, time
import requests
from bs4 import BeautifulSoup
s = sched.scheduler(time.time, time.sleep)
from urllib2 import Request
url=raw_input('enter the desired score card url here : ')
req=Request(url)
def do_something(sc) :
#global x
r=requests.get(url)
soup=BeautifulSoup(r.content)
for i in soup.find_all("div",{"id":"innings_1"}):
x=i.text.find('Batsman')
in_1=i.text
print(in_1[0:x])
for i in soup.find_all("div",{"id":"innings_2"}):
x=i.text.find('Batsman')
in_1=i.text
print(in_1[0:x])
for i in soup.find_all("div",{"id":"innings_3"}):
x=i.text.find('Batsman')
in_1=i.text
print(in_1[0:x])
for i in soup.find_all("div",{"id":"innings_4"}):
x=i.text.find('Batsman')
in_1=i.text
print(in_1[0:x])
# do your stuff
#do what ever
s.enter(5, 1, do_something, (sc,))
s.enter(5, 1, do_something, (s,))
s.run()
请注意,使用实际帐户的凭据,而不是使用9876543210作为用户名和abcdefghij作为密码
如果您想通过python脚本在中调用完全独立的python脚本,请在way2sms.com上注册这些凭据,请查看
子流程
模块。如果要通过python脚本在中调用完全独立的python脚本,可以使用subprocess.call
或subprocess.Popen
。您可以使用subprocess.call
或subprocess.Popen
如果不看一下代码,很难回答。但是,将管道与子流程结合使用似乎是一个合适的解决方案
请看这篇文章的答案:不看一下代码就很难回答。但是,将管道与子流程结合使用似乎是一个合适的解决方案
请参阅本文的答案:Hi,修改第一个程序以写入文件,修改第二个程序以从该文件读取。请发布您编写的代码。Hi,修改第一个程序以写入文件,修改第二个程序以从该文件读取。请发布您编写的代码。