Nov-25-2021, 08:51 PM
It's better to use schedule for this that run in a while true loop with time.sleep() added.
schedule would works fine this.
A example, so write to disk once then check against that file,if updated start again.
schedule would works fine this.
A example, so write to disk once then check against that file,if updated start again.
import schedule import time, datetime import requests from bs4 import BeautifulSoup def news(url): response = requests.get(url) soup = BeautifulSoup(response.content, 'lxml') news = soup.select_one('#link-0-0-p1').get('href') print('News run') with open('news.txt', 'w') as f: f.write(news) return schedule.CancelJob def check_update(url): response = requests.get(url) soup = BeautifulSoup(response.content, 'lxml') news_update = soup.select_one('#link-0-0-p1').get('href') with open('news.txt') as f: if news_update == f.read(): print('No update on site') print(datetime.datetime.utcnow()) else: print('Site has gotten updated') print(datetime.datetime.utcnow()) # Update start again once news(url) if __name__ == '__main__': url = 'https://www.binance.com/en/support/announcement/c-49?avId=49' schedule.every(10).seconds.do(news, url=url) schedule.every(60).seconds.do(check_update, url=url) while True: schedule.run_pending() time.sleep(1)