I'm trying to scrape recent releases of movies with the URL. But I want to be notified of each new release. I also want to set a timer, let's say every two hours the script will check for a new movie release. If there's a new release, it would be sent to my Telegram bot. I have no idea on how to go about that yet.
from bs4 import BeautifulSoup
from urllib.request import Request, urlopen
req = Request("https://www.thenetnaija.com/videos/movies", headers={'User-Agent': 'XYZ/3.0'})
webpage = urlopen(req, timeout=10)
b4 = BeautifulSoup(webpage, "html.parser")
movie_list = b4.find_all("div", {"class" : "video-files"})
for allContainers in movie_list:
filmName = allContainers.find('img').get('alt')
print(filmName)
CodePudding user response:
to send notification for you from telegram bot
1 - first talk to this bot: @userinfobot get the id
2 - get your bot token from @botfather
3 - send any message to your bot
(the above steps only one time)
4- make get request
https://api.telegram.org/bot{bot_token}/sendMessage?chat_id={chat_id}&text={notification_text}
CodePudding user response:
import time
from bs4 import BeautifulSoup
import requests
from urllib.request import Request, urlopen
req = Request("https://www.thenetnaija.com/videos/movies", headers={'User-Agent': 'XYZ/3.0'})
webpage = urlopen(req, timeout=10)
b4 = BeautifulSoup(webpage, "html.parser")
movie_list = b4.find_all("div", {"class" : "video-files"})
for allContainers in movie_list:
filmName = allContainers.find('img').get('alt')
printed = []
print(filmName)
while True:
if filmName not in printed:
requests.get("https://api.telegram.org/bot{"insert bot_token here"}/sendMessage?chat_id={"insert chat id here"}&text={}".format(filmName))
time.sleep(10)
printed.append(filmName)
Thanks so much @Aladdin Jiroun!