【问题标题】:Deploy a simple Python bot部署一个简单的 Python 机器人
【发布时间】:2020-05-28 15:15:32
【问题描述】:

代码:

    import requests as rq
    from bs4 import BeautifulSoup as bs

    url = "https://apod.nasa.gov/apod/astropix.html"
    page = rq.get(url).content
    soup = bs(page, 'html.parser')
    response = soup.find('img')
    if response == None:
        imglink = soup.find('iframe')['src']
    else:
        imglink = 'https://apod.nasa.gov/apod/' + response['src']
    def main():
        sess = rq.Session()
        cid='**************'
        turl = 'https://api.telegram.org/bot*******************/'
        if response == None:
            imglink = soup.find('iframe')['src']
            params = {'chat_id':cid,'text':imglink}
            sess.post(turl + 'sendMessage', data=params)
        else:
            imglink = 'https://apod.nasa.gov/apod/' + response['src']
            title = soup.find('b').get_text()
            params = {'chat_id':cid,'photo':imglink,'caption':title}
           sess.post(turl + 'sendPhoto', data=params)

    if __name__ == '__main__':
        main()

这是一个简单的机器人,用于将 Nasa 图片发送到我的电报频道。我将修改此脚本以使其每天都发生。但他的问题是我在哪里托管它们,这样它就会一直运行(免费)。正确的做法是什么。

【问题讨论】:

  • Heroku 有免费层:heroku.com 看看是否满足您的需求。
  • 我能知道具体的做法吗
  • 我添加了一个答案以及这样做的步骤。我有一个在 Heroku 免费层上运行的脚本,它运行良好。

标签: python deployment telegram


【解决方案1】:

我不知道有任何提供商会免费提供此服务。为了便宜,AWS 和 Google Cloud 都有简单的解决方案。

例如:https://cloud.google.com/blog/products/application-development/how-to-schedule-a-recurring-python-script-on-gcp

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-22
    • 2018-09-05
    • 1970-01-01
    • 2011-02-27
    • 2022-11-19
    • 2015-01-25
    • 1970-01-01
    • 2012-11-06
    相关资源
    最近更新 更多