mirror of
https://github.com/wolfswolke/DeathGarden_API_Rebirth.git
synced 2026-04-24 15:06:58 -05:00
Added logging to mongodb_handler.py and time_handler.py
This commit is contained in:
parent
f5c362231b
commit
cc4c1c03a8
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user