python - 部署一个简单的 Python 机器人
问题描述
代码:
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 图片发送到我的电报频道。我将修改此脚本以使其每天都发生。但他的问题是我在哪里托管它们,这样它就会一直运行(免费)。正确的做法是什么。
解决方案
我不知道有任何提供商会免费提供此服务。为了便宜,AWS 和 Google Cloud 都有简单的解决方案。
推荐阅读
- python - 如何将“.app”(使用 py2app 创建)从 Mac 共享到 iPhone?
- python - 添加二进制和数据文件时找不到 nltk_data
- node.js - Array.push() 似乎仅在我的应用程序运行时才工作
- android - “npm start”和“react-native run-android”部署有什么区别?
- android - 为 Android 编译 PDFium 的正确选项是什么?
- azure - Azure blob 存储:从浏览器上传时检查 blob mime 类型
- javascript - 如何使用javascript在html中显示文本文件中的文本
- javascript - React 扩展组件渲染函数调用
- php - 使用 PHP 的动态 CSS
- node.js - 如何附加文档和更新密钥