diff options
| author | A Farzat <a@farzat.xyz> | 2025-10-05 07:24:22 +0300 |
|---|---|---|
| committer | A Farzat <a@farzat.xyz> | 2025-10-05 07:24:22 +0300 |
| commit | 3b418daf684f01a126a56b58c83120af5914f576 (patch) | |
| tree | 20b6ea9487cce5a90cff8696085b8c3f7783db75 /data_collector.py | |
| parent | 66194a36af3d1f6897e8fd0e3b61388cb18f6e1f (diff) | |
| download | csca5028-3b418daf684f01a126a56b58c83120af5914f576.tar.gz csca5028-3b418daf684f01a126a56b58c83120af5914f576.zip | |
Remove the redundant scheduler class
This allows fetching the database every time, ensuring any updates to
the database between fetches as captured.
Diffstat (limited to 'data_collector.py')
| -rwxr-xr-x | data_collector.py | 23 |
1 files changed, 6 insertions, 17 deletions
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) |
