我已經編寫了一個代碼(python 2.7),去到一個網站Cricket score,然後從中取出一些數據來顯示它的分數。它也會定期重複並繼續運行,因爲分數不斷變化。 我也寫了一個代碼,用於從用戶接收消息輸入並將該消息作爲短信發送給我的號碼。我怎樣才能把一個python腳本的輸出作爲另一個python腳本的用戶輸入
我希望將這兩個俱樂部分開,以便我的屏幕上打印的分數作爲向我發送實時比分的消息輸入。
代碼
sms.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 = ""
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()
livematch.py
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()
注意,代替使用作爲用戶名和ABCDEFGHIJ作爲密碼使用的憑據實際帳戶。
註冊在way2sms.com對於那些憑據
嗨,修改第一個程序寫入,而不是文件和第二程序從該文件中讀取。 – theAlse
請發佈您寫的代碼。 –