Discord/modules/database.py

31 lines
903 B
Python
Raw 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()
for collection in ["users", "warnings", "scheduler"]:
if not collection in collections:
db.create_collection(collection)
col_users = db.get_collection("users")
col_warnings = db.get_collection("warnings")
# col_checkouts = db.get_collection("checkouts")
# col_trackings = db.get_collection("trackings")
# col_authorized = db.get_collection("authorized")
2023-05-04 17:14:23 +03:00
# col_transactions = db.get_collection("transactions")