From 3b418daf684f01a126a56b58c83120af5914f576 Mon Sep 17 00:00:00 2001 From: A Farzat Date: Sun, 5 Oct 2025 07:24:22 +0300 Subject: Remove the redundant scheduler class This allows fetching the database every time, ensuring any updates to the database between fetches as captured. --- data_collector.py | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) (limited to 'data_collector.py') diff --git a/data_collector.py b/data_collector.py index 9da9404..485d8af 100755 --- a/data_collector.py +++ b/data_collector.py @@ -1,24 +1,13 @@ #!/usr/bin/env python from time import sleep +from datetime import datetime, timedelta, UTC from components.database import subscriptions -from components.subscriptions.main import Subscription, default_scheduler - -subs_to_fetch = ["fiwzLy-8yKzIbsmZTzxDgw", "Ef0-WZoqYFzLZtx43KPvag", - "PF-oYb2-xN5FbCXy0167Gg", "hlgI3UHCOnwUGzWzbJ3H5w", ] -for id in subs_to_fetch: - sub_dict = subscriptions.find_one({"_id": "yt:channel:"+id}) - if sub_dict: - sub = Subscription(**sub_dict) - else: - sub = Subscription( - _id="yt:channel:"+id, - link="http://www.youtube.com/feeds/videos.xml?channel_id=UC"+id, - time_between_fetches=5, - ) - sub.insert() - sub.initialise_job() +from components.subscriptions.main import Subscription while True: - default_scheduler.run_pending() + for sub_dict in subscriptions.find(): + sub = Subscription(**sub_dict) + if datetime.now(tz=UTC) - sub.last_fetch > timedelta(seconds=sub.time_between_fetches): + sub.fetch() sleep(60) -- cgit v1.2.3-70-g09d2