From b6bdab5e02008965f052c4a1070be862ef3b5d47 Mon Sep 17 00:00:00 2001 From: A Farzat Date: Thu, 21 Aug 2025 06:56:41 +0300 Subject: Add database setup code --- data-collection/components/database.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 data-collection/components/database.py (limited to 'data-collection/components') diff --git a/data-collection/components/database.py b/data-collection/components/database.py new file mode 100644 index 0000000..72f63e6 --- /dev/null +++ b/data-collection/components/database.py @@ -0,0 +1,16 @@ +import atexit +from typing import Any, Dict +from pymongo import MongoClient +from pymongo.database import Database +from pymongo.collection import Collection +from components.subscriptions.typing import SubsDict +from components.users.typing import UserDict + +client: MongoClient[Any] = MongoClient("mongodb://localhost", tz_aware=True) +database: Database[Any] = client.get_database("youtube") +subscriptions: Collection[SubsDict] = database.get_collection("subscriptions") +users: Collection[UserDict] = database.get_collection("users") + +@atexit.register +def _cleanup() -> None: + client.close() -- cgit v1.2.3-70-g09d2