Added debug.py

This commit is contained in:
ZKWolf
2023-06-17 04:29:16 +02:00
parent a02f5e1fbf
commit 64444440f0
3 changed files with 61 additions and 0 deletions

43
src/endpoints/debug.py Normal file
View File

@@ -0,0 +1,43 @@
from flask_definitions import *
from logic.time_handler import get_time
from logic.mongodb_handler import mongo
@app.route("/debug", methods=["Get"])
def debug_root():
endpoint_descriptions = {
'/debug/user': 'Endpoint to debug user information',
'/debug/time': 'Endpoint to debug Epoch Time'}
endpoint_list = []
for endpoint, description in endpoint_descriptions.items():
endpoint_list.append(f'<li>{endpoint}: {description}</li>')
endpoints_html = '<ul>' + ''.join(endpoint_list) + '</ul>'
return f'<h1>Debug Endpoints:</h1>{endpoints_html}'
@app.route("/debug/user", methods=["Get"])
def debug_user():
if request.args.get('steamid') is None:
return jsonify({'error': 'No steamid. Please call with ?steamid=<steamID64>'}), 400
steam_id = request.args.get('steamid')
user_data = mongo.get_debug(steamid=steam_id, server=mongo_host, db=mongo_db, collection=mongo_collection)
user_data['_id'] = str(user_data.get('_id'))
steamid = user_data.get('steamid')
userId = user_data.get('userId')
eula = user_data.get('eula')
xp = user_data.get('xp')
currency_blood_cells = user_data.get('currency_blood_cells')
currency_iron = user_data.get('currency_iron')
currency_ink_cells = user_data.get('currency_ink_cells')
unlocked_items = user_data.get('unlocked_items')
return_data = {"steamid": steamid, "userId": userId, "eula": eula, "xp": xp, "currency_blood_cells": currency_blood_cells, "currency_iron": currency_iron, "currency_ink_cells": currency_ink_cells, "unlocked_items": unlocked_items}
return jsonify(return_data)
@app.route("/debug/time", methods=["Get"])
def debug_time():
current_time, expire_time = get_time()
return jsonify({'current_time': current_time, 'expire_time': expire_time})

View File

@@ -92,5 +92,22 @@ class Mongo:
print(e)
return None, None
def get_debug(self, steamid, server, db, collection):
try:
self.dyn_server = server
self.dyn_db = db
self.dyn_collection = collection
client = pymongo.MongoClient(self.dyn_server)
self.dyn_db = client[self.dyn_db]
self.dyn_collection = self.dyn_db[self.dyn_collection]
existing_document = self.dyn_collection.find_one({'steamid': steamid})
if existing_document:
return existing_document
else:
return {"status": "error", "message": "No user found with steamid: " + steamid}
except Exception as e:
print(e)
return {"status": "error", "message": "Error in mongodb_handler"}
mongo = Mongo()

View File

@@ -12,6 +12,7 @@ import endpoints.unknown
import endpoints.user_handeling
import endpoints.general
import endpoints.logging
import endpoints.debug
# ------------------------------------------------------- #