Code:
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()
This is a simple bot for sending Nasa picture to my telegram channel. I will be modifying this script to make it happen everyday. But he Question is where do I host them, So that it will run all the time (free). What is the correct way of doing it.
I don't know of any providers that would host this for free. For cheap, AWS and Google Cloud all have simple solutions.
See if https://www.heroku.com free tier would meet your needs.
git init
Procfile
, and in it put:worker: python your_script_name_here.py
git push origin heroku
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.