This repository has been archived on 2024-08-21. You can view files and clone it, but cannot push or open issues or pull requests.
EmojiCaptchaBot/modules/database.py

35 lines
1020 B
Python
Raw Normal View History

2023-08-10 14:05:40 +03:00
"""Module that provides all database columns"""
2023-08-11 16:04:21 +03:00
from async_pymongo import AsyncClient
2023-08-10 14:05:40 +03:00
from ujson import loads
with open("config.json", "r", encoding="utf-8") as f:
db_config = loads(f.read())["database"]
f.close()
if db_config["user"] is not None and db_config["password"] is not None:
con_string = "mongodb://{0}:{1}@{2}:{3}/{4}".format(
db_config["user"],
db_config["password"],
db_config["host"],
db_config["port"],
db_config["name"],
)
else:
con_string = "mongodb://{0}:{1}/{2}".format(
db_config["host"], db_config["port"], db_config["name"]
)
2023-08-11 16:04:21 +03:00
db_client = AsyncClient(con_string)
2023-08-10 14:05:40 +03:00
db = db_client.get_database(name=db_config["name"])
2023-08-11 16:04:21 +03:00
# collections = db.list_collection_names()
2023-08-10 14:05:40 +03:00
2023-08-11 16:04:21 +03:00
# for collection in ["users", "groups", "schedule"]:
# if collection not in collections:
# db.create_collection(collection)
2023-08-10 14:05:40 +03:00
col_users = db.get_collection("users")
2023-08-11 16:04:21 +03:00
col_groups = db.get_collection("groups")
2023-08-10 14:05:40 +03:00
col_schedule = db.get_collection("schedule")