from time import sleep from requests import get from helpers.mongo import mongo def fetch_jokes(): i = 1 while True: info = get(f"https://baneks.ru/{i}") if info.status_code == 200: print(i) content = info.text anek = content.split("

")[1].split("

")[0].replace("
", "") if '' in anek: break if mongo.jokes_collection.find_one({"id": i}) is None: mongo.jokes_collection.insert_one({ "id": i, "text": anek }) i += 1 def poll_jokes(): while True: print("start fetching jokes") fetch_jokes() print("finished fetching jokes") sleep(60 * 60 * 24)