Added logging to mongodb_handler.py and time_handler.py

This commit is contained in:
ZKWolf 2023-06-08 20:37:03 +02:00
parent f5c362231b
commit cc4c1c03a8
2 changed files with 36 additions and 25 deletions

View File

@ -1,29 +1,34 @@
import pymongo
import uuid
import logging
logger = logging.getLogger(__name__)
def user_db_handler(steamid, server, db, collection):
client = pymongo.MongoClient(server)
db = client[db]
collection = db[collection]
try:
client = pymongo.MongoClient(server)
db = client[db]
collection = db[collection]
existing_document = collection.find_one({'steamid': steamid})
existing_document = collection.find_one({'steamid': steamid})
if existing_document:
print(f"Document with steamid {steamid} already exists.")
userId = existing_document['userId']
token = existing_document['token']
return userId, token
else:
userId = str(uuid.uuid4())
token = str(uuid.uuid4())
if existing_document:
print(f"Document with steamid {steamid} already exists.")
userId = existing_document['userId']
token = existing_document['token']
return userId, token
else:
userId = str(uuid.uuid4())
token = str(uuid.uuid4())
new_document = {
'steamid': steamid,
'userId': userId,
'token': token
}
collection.insert_one(new_document)
return userId, token
new_document = {
'steamid': steamid,
'userId': userId,
'token': token
}
collection.insert_one(new_document)
return userId, token
except Exception as e:
logger.error("Error in mongodb_handler -> " + str(e))
return None, None

View File

@ -1,11 +1,17 @@
import datetime
import logging
logger = logging.getLogger(__name__)
def get_time():
current_datetime = datetime.datetime.now()
current_timestamp = int(current_datetime.timestamp())
try:
current_datetime = datetime.datetime.now()
current_timestamp = int(current_datetime.timestamp())
duration = 86400
expiration_timestamp = current_timestamp + duration
duration = 86400
expiration_timestamp = current_timestamp + duration
return current_timestamp, expiration_timestamp
return current_timestamp, expiration_timestamp
except Exception as e:
logger.error("Error in time_handler -> " + str(e))
return None, None