aboutsummaryrefslogtreecommitdiff
path: root/data_collector/utils.py
diff options
context:
space:
mode:
authorA Farzat <a@farzat.xyz>2025-10-11 09:15:07 +0300
committerA Farzat <a@farzat.xyz>2025-10-11 09:15:07 +0300
commit3145e87a434552fdf93a17a995c0f5bd68e8aa24 (patch)
treedae29008ccb03a1b47f5474346639e81b7273852 /data_collector/utils.py
parent5bbd9bda00e861f72f42965d407ada3ea6f5760e (diff)
downloadcsca5028-3145e87a434552fdf93a17a995c0f5bd68e8aa24.tar.gz
csca5028-3145e87a434552fdf93a17a995c0f5bd68e8aa24.zip
Organize data_collector to be similar to data_analyser
Diffstat (limited to 'data_collector/utils.py')
-rw-r--r--data_collector/utils.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/data_collector/utils.py b/data_collector/utils.py
new file mode 100644
index 0000000..6ca5c69
--- /dev/null
+++ b/data_collector/utils.py
@@ -0,0 +1,13 @@
+from datetime import datetime, timedelta, UTC
+
+from pymongo.collection import Collection
+
+from components.subscriptions.main import Subscription
+from components.subscriptions.typing import SubsDict
+
+def collect_data(subs_collection: Collection[SubsDict]) -> None:
+ for sub_dict in subs_collection.find():
+ sub = Subscription(**sub_dict)
+ sub._collection = subs_collection
+ if datetime.now(tz=UTC) - sub.last_fetch > timedelta(seconds=sub.time_between_fetches):
+ sub.fetch()