From 8cac75d8d59e62dd73bd209d70e0613f0dc2597b Mon Sep 17 00:00:00 2001 From: 2000-Trek Date: Wed, 5 Jul 2023 22:23:42 +0200 Subject: [PATCH] new api feuture --- main.py | 20 ++++++++++++++++++++ templates/documentation.html | 1 - 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 364c707..5167ddf 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +from crypt import methods from fileinput import filename import queue, sqlite3, time, atexit, sys, uuid, json, urllib.parse, logging, datetime, os from flask import Flask, render_template, request, make_response, session, url_for @@ -270,6 +271,25 @@ def request_removetag(data): leave_room(session[id]) #api +@app.route("/api/change", methods=['GET']) +def api_change(): + userid = request.args.get("id") + c.execute("SELECT * FROM users WHERE id=?", [userid]) + user_list = c.fetchall() + if user_list != []: + user = user_list[0] + try: + change = int(request.args.get("change")) + except: + return make_response(json.dumps({"mode":"error","error":"095"})) + if change == None: + change = 1 + c.execute(f"UPDATE users SET balance = balance + {change} WHERE id={user[0]}") + db_log.info(f"Changed the balance from user {user[0]} from {balance_old} to {user[2]}") + socketio.emit("update", "update") + return make_response(json.dumps({"mode":"balance", "username":user[1], "balance":user[2]})) + + @app.route("/api/tag_id", methods=['GET']) def get_id(): global finished diff --git a/templates/documentation.html b/templates/documentation.html index da4fa2b..576ead3 100644 --- a/templates/documentation.html +++ b/templates/documentation.html @@ -12,7 +12,6 @@

Documentation

http://matekasse.server.c3h/api/tag_id?={tag_id}

-

response:

 

API: