简体   繁体   English

如何将一个python脚本的输出作为另一个python脚本的用户输入

[英]How can i take the output of one python script as user input for another python script

i have written a code (python 2.7) that goes to a website Cricket score and then takes out some data out of it to display just its score .It also periodically repeats and keeps running because the scores keep changing. 我写了一个代码(python 2.7),进入一个网站Cricket得分 ,然后从中取出一些数据,只显示其得分。它也会定期重复并继续运行,因为分数不断变化。 i have also written a code for taking a message input from user and send that message as an sms to my number . 我还编写了一个代码,用于从用户那里获取消息输入,并将该消息作为短信发送到我的号码。

i want to club these two so that the scores printed on my screen serve as the message input for sending live scores to me. 我想将这两个分开,以便我的屏幕上打印的分数作为向我发送实时分数的消息输入。

codes are 代码是

sms.py 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 = "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 ()    

livematch.py 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()

note that instead of using 9876543210 as username and abcdefghij as password use the credentials of actual account. 请注意,不使用9876543210作为用户名,而使用abcdefghij作为密码,请使用实际帐户的凭据。

sign up at way2sms.com for those credentials 在way2sms.com上注册这些凭据

If you want to call a completly independed python script in via your python script take a look at subprocess module. 如果你想通过你的python脚本调用一个完全独立的python脚本,请看subprocess模块。 You could use subprocess.call or subprocess.Popen . 您可以使用subprocess.callsubprocess.Popen

It is hard to answer without having a look at your code. 没有看你的代码就很难回答。 But it seems that using piping with subprocess would be an appropriate solution. 但似乎使用带有子流程的管道将是一个合适的解决方案。

See the answer on this post: python subprocess.stdout.readline doesn't 请参阅这篇文章的答案: python subprocess.stdout.readline没有

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从另一个 python 脚本向 python 脚本发送多个“用户输入”? - How can I send multiple “user input” to python script from another python script? 一个Python脚本为另一个python脚本提供“用户输入” - One Python script giving “user input” to another python script 如何获取可变数量的文件作为python脚本的输入? - How can I take a variable number of files as input for a python script? 如何在Python中将用户输入从一个脚本传递到另一个脚本? - How to pass user input from one script to another in Python? 如何使用python脚本的输出作为RASA的输入,而不是通常的用户输入? - How can I use the output of a python script as RASA’s input instead of the usual user input? 我如何从 python 读取特定终端 output 作为另一个脚本的输入 - How can i read a particular terminal output from python as input in another script 如何从PHP上的python脚本获取实时输入输出 - How to take real time input output from a python script on PHP 如何将一个python脚本的输出传递给另一个python脚本 - How do I pipe output of one python script to another python script 如何将一个 python 脚本的输入也分配为另一个脚本的输入 - How do I assign an input from one python script to be an input in another script as well 如何编写 python 代码以通过 bash 脚本从用户那里获取输入 - How can write python code to take input from user via bash script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM