diff options
| author | A Farzat <a@farzat.xyz> | 2025-10-11 09:15:07 +0300 |
|---|---|---|
| committer | A Farzat <a@farzat.xyz> | 2025-10-11 09:15:07 +0300 |
| commit | 3145e87a434552fdf93a17a995c0f5bd68e8aa24 (patch) | |
| tree | dae29008ccb03a1b47f5474346639e81b7273852 | |
| parent | 5bbd9bda00e861f72f42965d407ada3ea6f5760e (diff) | |
| download | csca5028-3145e87a434552fdf93a17a995c0f5bd68e8aa24.tar.gz csca5028-3145e87a434552fdf93a17a995c0f5bd68e8aa24.zip | |
Organize data_collector to be similar to data_analyser
| -rwxr-xr-x | data_collector/__main__.py | 10 | ||||
| -rw-r--r--[-rwxr-xr-x] | data_collector/utils.py (renamed from data_collector.py) | 14 |
2 files changed, 17 insertions, 7 deletions
diff --git a/data_collector/__main__.py b/data_collector/__main__.py new file mode 100755 index 0000000..11791c2 --- /dev/null +++ b/data_collector/__main__.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python + +from time import sleep +from components.database import subscriptions + +from .utils import collect_data + +while True: + collect_data(subscriptions) + sleep(60) diff --git a/data_collector.py b/data_collector/utils.py index 485d8af..6ca5c69 100755..100644 --- a/data_collector.py +++ b/data_collector/utils.py @@ -1,13 +1,13 @@ -#!/usr/bin/env python - -from time import sleep from datetime import datetime, timedelta, UTC -from components.database import subscriptions + +from pymongo.collection import Collection + from components.subscriptions.main import Subscription +from components.subscriptions.typing import SubsDict -while True: - for sub_dict in subscriptions.find(): +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() - sleep(60) |
