From 0ef49fade8a959d8c48aa600733df3575189bf2d Mon Sep 17 00:00:00 2001 From: MoonDev Date: Sun, 4 May 2025 16:30:07 +0300 Subject: [PATCH] first commit --- main.py | 32 +++++++++++++++++ .../__pycache__/random_string.cpython-312.pyc | Bin 0 -> 817 bytes misc/conversations.py | 33 ++++++++++++++++++ misc/random_string.py | 10 ++++++ 4 files changed, 75 insertions(+) create mode 100644 main.py create mode 100644 misc/__pycache__/random_string.cpython-312.pyc create mode 100644 misc/conversations.py create mode 100644 misc/random_string.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..291a9c7 --- /dev/null +++ b/main.py @@ -0,0 +1,32 @@ +from flask import Flask, request, jsonify +from misc.random_string import generate_secure_string + + +app = Flask(__name__) + +@app.route('/') +def index(): + return "Добро пожаловать на Flask сервер!" + +@app.route('/api/new-request', methods=['POST']) +def handle_data(): + # Получаем JSON из запроса + data = request.get_json() + + if not data: + return jsonify({"error": "No JSON payload received"}), 400 + + # Выводим полученные данные в консоль + print("Полученные данные:", data) + + # Формируем ответ + response = { + "message": "Data received successfully", + "yourData": data, + "conversation_id":generate_secure_string(40) + } + + return jsonify(response), 200 + +if __name__ == '__main__': + app.run(debug=True) \ No newline at end of file diff --git a/misc/__pycache__/random_string.cpython-312.pyc b/misc/__pycache__/random_string.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..682853bf018b71747d7a2ad73dfcf32367d34b65 GIT binary patch literal 817 zcmZuvL2DCH5PolWvuPVv*;FdpgHh;Vg=PiOfP~<|h$!SDcnC;Xcc0l!HoM`yjWIQW zparc6DyZ@3wN%kU5B>))Ej_fn9`&G}gj}j8=QY_tw6wJQ z6Y#6}h>tWjh9|)oAO|_vN97UXGIpdzRF*o}kbj88l8wjt0#pzgWcU`;V?01zxLt=r z6nCTue4|r~d&CaF15xFGdu%QMK84=3nAH`uGIqwEo5)Z~ zR1o0kAMT>-d63~XP_OX~gkkzFx_ttn9**{>JdFF26jy(P2Nz-w{Ls~aot8PVM zFyAJ3Osnac4UgF-wE`z>R9Hm4pqg!V_+-9H0&>4e3k!y@s1=b4bZ$|AQC8j$ZOdnc z?0%})8Jh*Q`yK7}(R#YL+WU0+Rc=stS$KDLYkGdQ_nV2;JUVp-8wswCDsjzXw&zuR z5((~Hb-bzv11h!93wQ#!RS68P`Xs1EE)}nhiJfOI(-Z)oIh-J!hM?%iE`b6*+ez(( z{_w%}QT>~Kd`q9((C6N(AGKv|L%-0!zMayZ=azDt>Ec@J^R2ZW7@Mi$x>6j%ZDhz) xyho}DB?>PidQ8}R3?}l8&}sRkKxe=welOEO{gN@pJLt#`(uPU`U&VV@{sQZWxF7%k literal 0 HcmV?d00001 diff --git a/misc/conversations.py b/misc/conversations.py new file mode 100644 index 0000000..e33412d --- /dev/null +++ b/misc/conversations.py @@ -0,0 +1,33 @@ +from random_string import generate_secure_string + +CONVERSATIONS = {} +""" +{ +messages: + [{ + role:str, + content:str, + id:int + }], +last_message_id: int, +workspace: str, +user_name: str, +problem_type: int +} + +""" + +class Conversations: + def __init__(self): + self.id = "" + + def create(self,user_message,workspace,user_name,problem_type): + self.id = generate_secure_string(40) + CONVERSATIONS[self.id] = { + "messages":[], + "last_message_id":0, + "workspace":workspace, + "user_name":user_name, + "problem_type":problem_type} + return CONVERSATIONS[self.id] + diff --git a/misc/random_string.py b/misc/random_string.py new file mode 100644 index 0000000..9c641d7 --- /dev/null +++ b/misc/random_string.py @@ -0,0 +1,10 @@ +import secrets +import string + +def generate_secure_string(length): + if length <= 0: + return "" + + characters = string.ascii_letters + string.digits + return ''.join(secrets.choice(characters) for _ in range(length)) +