Discord/modules/database.py

28 lines
759 B
Python
Raw Permalink Normal View History

2023-05-04 17:09:47 +03:00
from pymongo import MongoClient
from ujson import loads
with open("config.json", "r", encoding="utf-8") as f:
db_config = loads(f.read())["database"]
f.close()
db_client = MongoClient(
2023-05-04 17:14:23 +03:00
"mongodb://{0}:{1}@{2}:{3}/{4}".format(
2023-05-04 17:09:47 +03:00
db_config["user"],
db_config["password"],
db_config["host"],
db_config["port"],
2023-05-04 17:14:23 +03:00
db_config["name"],
2023-05-04 17:09:47 +03:00
)
)
db = db_client.get_database(name=db_config["name"])
collections = db.list_collection_names()
2023-05-06 18:52:46 +03:00
for collection in ["users", "warnings", "scheduler", "analytics"]:
2023-05-04 17:09:47 +03:00
if not collection in collections:
db.create_collection(collection)
col_users = db.get_collection("users")
col_warnings = db.get_collection("warnings")
2023-05-06 18:52:46 +03:00
col_analytics = db.get_collection("analytics")