From 6b33df608127a7e6d6acbd6e1c89c2430c3f4e25 Mon Sep 17 00:00:00 2001 From: ada-dmitry Date: Tue, 22 Aug 2023 14:32:09 +0300 Subject: [PATCH 01/13] update 0.1 --- .vscode/settings.json | 6 ++++++ app.py | 14 ++++++++++++++ db.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 db.py diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..5c80254 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "[python]": { + "editor.defaultFormatter": "ms-python.autopep8" + }, + "python.formatting.provider": "none" +} diff --git a/app.py b/app.py index 43d35e8..18f1e43 100644 --- a/app.py +++ b/app.py @@ -7,6 +7,20 @@ app = Flask(__name__) def hello_world(): # put application's code here return 'Hello World!' +@app.route('/create_game') +def create(str truechatid): + + + + + +@app.route('/start_game') +def start(): # Команда принимает на вход + + +@app.route('/action') +def action(): + if __name__ == '__main__': app.run() \ No newline at end of file diff --git a/db.py b/db.py new file mode 100644 index 0000000..ad26ec7 --- /dev/null +++ b/db.py @@ -0,0 +1,28 @@ +import psycopg2 + + +db_params = { + 'host': '51.250.68.42', + 'database': 'test', + 'user': 'curator', + 'password': '4oumQk' +} + + +try: + connection = psycopg2.connect(**db_params) + cursor = connection.cursor() + + # Ваш код выполнения запросов + + cursor.execute("SELECT * FROM chats") + rows = cursor.fetchall() + + for row in rows: + print(row) + + cursor.close() + connection.close() + +except Exception as e: + print("Ошибка:", e) \ No newline at end of file From 3e6834ed8741b752ec4b5f65ae7e296678e67703 Mon Sep 17 00:00:00 2001 From: ada-dmitry Date: Tue, 22 Aug 2023 15:02:37 +0300 Subject: [PATCH 02/13] update 0.2 --- app.py | 8 ++++---- db.py | 39 +++++++++++++++++++++++++++++---------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/app.py b/app.py index 18f1e43..8f0d75e 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,4 @@ -from flask import Flask +from flask import Flask, request app = Flask(__name__) @@ -7,16 +7,16 @@ app = Flask(__name__) def hello_world(): # put application's code here return 'Hello World!' -@app.route('/create_game') +@app.route('/create_game', method = ["POST"]) def create(str truechatid): - + @app.route('/start_game') def start(): # Команда принимает на вход - + @app.route('/action') def action(): diff --git a/db.py b/db.py index ad26ec7..7e500e4 100644 --- a/db.py +++ b/db.py @@ -8,21 +8,40 @@ db_params = { 'password': '4oumQk' } +connection = psycopg2.connect(**db_params) +cursor = connection.cursor() -try: - connection = psycopg2.connect(**db_params) - cursor = connection.cursor() +def query_ins_user(str x): + try: + # Запрос добавления пользователя + cursor.execute(f"""INSERT into public.Users(TrueUserID, role, isAlive) values ({x}, 0)""") + cursor.commit() + except Exception as e: + print("Ошибка:", e) + - # Ваш код выполнения запросов +def query_ins_chat(str x): + try: # Запрос добавления чата + cursor.execute(f"""INSERT into public.Chats(TrueChatID, StateID) values ({x}, 0)""") + cursor.commit() + except Exception as e: + print("Ошибка:", e) + - cursor.execute("SELECT * FROM chats") - rows = cursor.fetchall() - for row in rows: - print(row) +def query_sel(str x): + try: + # Запрос вывода из БД + cursor.execute("SELECT * FROM chats") + rows = cursor.fetchall() + # for row in rows: + # print(row) + + except Exception as e: + print("Ошибка:", e) + +def close(cur = cursor, conn = connection): cursor.close() connection.close() -except Exception as e: - print("Ошибка:", e) \ No newline at end of file From 767468da741509116b1bb20590c4ebbe724250c1 Mon Sep 17 00:00:00 2001 From: ada-dmitry Date: Tue, 22 Aug 2023 15:16:49 +0300 Subject: [PATCH 03/13] add insUser + insChat --- db.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/db.py b/db.py index 7e500e4..bed411e 100644 --- a/db.py +++ b/db.py @@ -11,29 +11,29 @@ db_params = { connection = psycopg2.connect(**db_params) cursor = connection.cursor() -def query_ins_user(str x): +def query_ins_user(str x, curs = cursor): try: # Запрос добавления пользователя - cursor.execute(f"""INSERT into public.Users(TrueUserID, role, isAlive) values ({x}, 0)""") - cursor.commit() + curs.execute(f"""INSERT into public.Users(TrueUserID, role, isAlive) values ({x}, 0)""") + curs.commit() except Exception as e: print("Ошибка:", e) -def query_ins_chat(str x): +def query_ins_chat(str x, curs = cursor): try: # Запрос добавления чата - cursor.execute(f"""INSERT into public.Chats(TrueChatID, StateID) values ({x}, 0)""") - cursor.commit() + curs.execute(f"""INSERT into public.Chats(TrueChatID, StateID) values ({x}, 0)""") + curs.commit() except Exception as e: print("Ошибка:", e) -def query_sel(str x): +def query_sel(str x, curs = cursor): try: # Запрос вывода из БД - cursor.execute("SELECT * FROM chats") - rows = cursor.fetchall() + curs.execute("SELECT * FROM chats") + rows = curs.fetchall() # for row in rows: # print(row) @@ -41,6 +41,11 @@ def query_sel(str x): except Exception as e: print("Ошибка:", e) +def query_change(str x): + # Написать выдачу резов по ролям + + + def close(cur = cursor, conn = connection): cursor.close() connection.close() From aaf66b516b7a226449b157a76f6843844e4e085c Mon Sep 17 00:00:00 2001 From: ada-dmitry Date: Tue, 22 Aug 2023 15:19:36 +0300 Subject: [PATCH 04/13] a --- db.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/db.py b/db.py index bed411e..8b85110 100644 --- a/db.py +++ b/db.py @@ -11,7 +11,7 @@ db_params = { connection = psycopg2.connect(**db_params) cursor = connection.cursor() -def query_ins_user(str x, curs = cursor): +def query_ins_user(x, curs = cursor): try: # Запрос добавления пользователя curs.execute(f"""INSERT into public.Users(TrueUserID, role, isAlive) values ({x}, 0)""") @@ -20,7 +20,7 @@ def query_ins_user(str x, curs = cursor): print("Ошибка:", e) -def query_ins_chat(str x, curs = cursor): +def query_ins_chat(x, curs = cursor): try: # Запрос добавления чата curs.execute(f"""INSERT into public.Chats(TrueChatID, StateID) values ({x}, 0)""") curs.commit() @@ -29,7 +29,7 @@ def query_ins_chat(str x, curs = cursor): -def query_sel(str x, curs = cursor): +def query_sel(x, curs = cursor): try: # Запрос вывода из БД curs.execute("SELECT * FROM chats") @@ -41,9 +41,9 @@ def query_sel(str x, curs = cursor): except Exception as e: print("Ошибка:", e) -def query_change(str x): +def query_change(x): # Написать выдачу резов по ролям - + return 0 def close(cur = cursor, conn = connection): From 8e0562778296bb5c546be5eb84e36c09d2990bae Mon Sep 17 00:00:00 2001 From: ada-dmitry Date: Tue, 22 Aug 2023 15:44:27 +0300 Subject: [PATCH 05/13] del set --- .gitignore | 3 ++- __pycache__/db.cpython-311.pyc | Bin 0 -> 2413 bytes app.py | 12 +++++++----- db.py | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 __pycache__/db.cpython-311.pyc diff --git a/.gitignore b/.gitignore index f5e96db..a8b57ed 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -venv \ No newline at end of file +venv +setiings.json diff --git a/__pycache__/db.cpython-311.pyc b/__pycache__/db.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..bf498f9881cf8a13b628e8791bbf850a6396b622 GIT binary patch literal 2413 zcmds2-%A`v9G}^pJ9p1p<8Q4=>_*czml#n=LJ6TDYC*8qCTE*^2xh$-6pKv@O&qOq@VbWJ;!N64Ph;KPOQvA&Ra` zyI&$R7)KO;g&*LkOyxCFTCW_}Ve+`V5G9mMVY6xpM|~br0Qo(n0;)0tODL*PLggvR ztcDfU#1RzIeistL^TD&d-F;_!y3f7ceWuSPHs!Wk6-zV2wwUWbW2L7r-UtzwT(f|o zn1*dk8l1W$%_(!0l)?Fo#mrb)0T3$Gmf_w00mv#+(E?rr^lCHl0{RTh@rAsOK_z&L z4T~M+S!q>_`&Gwa(g^BAc7>UaBX)REva9xXneu|P4(EGZJ|jkBuyawmEs6a_G=pc* ztUQKhaEOHGFARqxLzhPNc+$4?RC+QIk9B_t8uJsQEKLO(9_-SYm7raEocAZnC24F1;u8LW3hXUuKt`pPVPo&(8PfH;7wBXK5^LQ`aA}rl;e!s}9Y^Xv&UT zN!OQR@VgD!#j`E}4{#S#F6^l5`pX{k{P<;y-54LR%y{zZ_$8XMc-$VJHm2gngprC@ zAak-iHRsmcOj9;D5l`|7;Vaexl4{`Pvp_PaAo+Y9TT1X@a3$z8O*kK27S!umu&-l}Y%1Ea_2_0+IhIq7IS2I}XayNI!MNQBKfimr z7d;8|H_N}&_SeZz>wEzJZvk}ffB+h}X4u655=aD4#5Qa?Jh&G+tQzdYf`W+fVf8>t zF~FK(Qt8$hNMUWTC|p~1EAe#*zjsK|R*B}6sG~&xd$+PyIKja#{02CG zT?77I?k{?|dqD2X`*L4ekPpm#`L?{9`+zEPUk=YVM21F&21fOh`n#9je@_=y=AKJJ zgoy-ll__e&Y9hgEVan=&0INY@5#BCg)(mG&0J$hkkiL4+cWN;uIZd#3!4O|0frxBW zE3)xqRymbZPC3e{{Go=2iz|!w?%cn#OvJPEB7lNTd+Fz)f0l#X%fZlT^j)C8UjDJR zUz49|K7g^xk}I%R#Qgxo-4#I_IJ|*E*wd5?{;pcVqFP{* Date: Tue, 22 Aug 2023 15:46:37 +0300 Subject: [PATCH 06/13] Delete settings.json --- .vscode/settings.json | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 5c80254..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "[python]": { - "editor.defaultFormatter": "ms-python.autopep8" - }, - "python.formatting.provider": "none" -} From c1ebc405d4744ce0042e289acdc1fe2a34fe9b26 Mon Sep 17 00:00:00 2001 From: ada-dmitry Date: Tue, 22 Aug 2023 15:47:26 +0300 Subject: [PATCH 07/13] upd 0.3 --- .gitignore | 1 + app.py | 13 +++++++------ db.py | 22 ++++++++++++---------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index a8b57ed..6b638aa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ venv setiings.json +.vscode \ No newline at end of file diff --git a/app.py b/app.py index a799b02..a69f6be 100644 --- a/app.py +++ b/app.py @@ -8,21 +8,22 @@ app = Flask(__name__) def hello_world(): # put application's code here return 'Hello World!' -@app.route('/create_game', methods = ["POST"]) + +@app.route('/create_game', methods=["POST"]) def create(): TCI = request.json db.query_ins_chat(TCI) - - @app.route('/start_game') -def start(): # Команда принимает на вход +def start(): # Команда принимает на вход pass + @app.route('/action') -def action(): +def action(): pass + if __name__ == '__main__': - app.run() \ No newline at end of file + app.run() diff --git a/db.py b/db.py index 1cb4039..b14e3fa 100644 --- a/db.py +++ b/db.py @@ -11,25 +11,27 @@ db_params = { connection = psycopg2.connect(**db_params) cursor = connection.cursor() -def query_ins_user(x, curs = cursor): + +def query_ins_user(x, curs=cursor): try: # Запрос добавления пользователя - curs.execute(f"""INSERT into public.Users(TrueUserID, role, isAlive) values ({x}, 0)""") + curs.execute( + f"""INSERT into public.Users(TrueUserID, role, isAlive) values ({x}, 0)""") curs.commit() except Exception as e: print("Ошибка:", e) - -def query_ins_chat(x, curs = cursor): - try: # Запрос добавления чата - curs.execute(f"""INSERT into public.Chats(TrueChatID, StateID) values ({x}, 0)""") + +def query_ins_chat(x, curs=cursor): + try: # Запрос добавления чата + curs.execute( + f"""INSERT into public.Chats(TrueChatID, StateID) values ({x}, 0)""") curs.commit() except Exception as e: print("Ошибка:", e) - -def query_sel(x, curs = cursor): +def query_sel(x, curs=cursor): try: # Запрос вывода из БД curs.execute("SELECT * FROM chats") @@ -41,12 +43,12 @@ def query_sel(x, curs = cursor): except Exception as e: print("Ошибка:", e) + def query_change(x): # Написать выдачу резов по ролям pass -def close(cur = cursor, conn = connection): +def close(cur=cursor, conn=connection): cursor.close() connection.close() - From b80e790ddc3777e7c041bdbbef4dcb29f4810315 Mon Sep 17 00:00:00 2001 From: ada-dmitry Date: Tue, 22 Aug 2023 16:02:01 +0300 Subject: [PATCH 08/13] ready create --- app.py | 8 +++++--- db.py | 23 +++++++++++++---------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/app.py b/app.py index a69f6be..5825b32 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,5 @@ from flask import Flask, request -# import db +import db app = Flask(__name__) @@ -11,8 +11,10 @@ def hello_world(): # put application's code here @app.route('/create_game', methods=["POST"]) def create(): - TCI = request.json - db.query_ins_chat(TCI) + TCI = request.json['chatID'] + curs = db.conn() + db.query_ins_chat(TCI, curs) + db.close(curs) @app.route('/start_game') diff --git a/db.py b/db.py index b14e3fa..5651983 100644 --- a/db.py +++ b/db.py @@ -8,30 +8,34 @@ db_params = { 'password': '4oumQk' } -connection = psycopg2.connect(**db_params) -cursor = connection.cursor() +# connection = psycopg2.connect(**db_params) #запускаем один раз -def query_ins_user(x, curs=cursor): +def conn(conn=connection): + cursor = conn.cursor() + return cursor + + +def query_ins_user(tui, curs=cursor): try: # Запрос добавления пользователя curs.execute( - f"""INSERT into public.Users(TrueUserID, role, isAlive) values ({x}, 0)""") - curs.commit() + f"""INSERT into public.Users(TrueUserID, role, isAlive) values ({tui}, 0)""") + conn.commit() except Exception as e: print("Ошибка:", e) -def query_ins_chat(x, curs=cursor): +def query_ins_chat(tci, curs=cursor): try: # Запрос добавления чата curs.execute( - f"""INSERT into public.Chats(TrueChatID, StateID) values ({x}, 0)""") - curs.commit() + f"""INSERT into public.Chats(TrueChatID, StateID) values ({tci}, 0)""") + conn.commit() except Exception as e: print("Ошибка:", e) -def query_sel(x, curs=cursor): +def query_sel(query, curs=cursor): try: # Запрос вывода из БД curs.execute("SELECT * FROM chats") @@ -51,4 +55,3 @@ def query_change(x): def close(cur=cursor, conn=connection): cursor.close() - connection.close() From 713525aa38c396436c934169c1a4091e2a13c4e8 Mon Sep 17 00:00:00 2001 From: ada-dmitry Date: Tue, 22 Aug 2023 16:17:23 +0300 Subject: [PATCH 09/13] upd --- db.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db.py b/db.py index 5651983..f1610d6 100644 --- a/db.py +++ b/db.py @@ -3,12 +3,12 @@ import psycopg2 db_params = { 'host': '51.250.68.42', - 'database': 'test', + 'database': 'postgres', 'user': 'curator', 'password': '4oumQk' } -# connection = psycopg2.connect(**db_params) #запускаем один раз +connection = psycopg2.connect(**db_params) # запускаем один раз def conn(conn=connection): From 70da42077eaf2cb68c49bc772c008eac31afed07 Mon Sep 17 00:00:00 2001 From: ada-dmitry Date: Tue, 22 Aug 2023 16:22:13 +0300 Subject: [PATCH 10/13] mod1 --- app.py | 2 +- db.py | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/app.py b/app.py index 5825b32..cbd5f51 100644 --- a/app.py +++ b/app.py @@ -12,7 +12,7 @@ def hello_world(): # put application's code here @app.route('/create_game', methods=["POST"]) def create(): TCI = request.json['chatID'] - curs = db.conn() + cursor = db.connection.cursor() db.query_ins_chat(TCI, curs) db.close(curs) diff --git a/db.py b/db.py index f1610d6..cc28068 100644 --- a/db.py +++ b/db.py @@ -11,11 +11,6 @@ db_params = { connection = psycopg2.connect(**db_params) # запускаем один раз -def conn(conn=connection): - cursor = conn.cursor() - return cursor - - def query_ins_user(tui, curs=cursor): try: # Запрос добавления пользователя From ccd22c788b23de55e34a67b75b612d7ba53e2d4e Mon Sep 17 00:00:00 2001 From: ada-dmitry Date: Tue, 22 Aug 2023 16:23:08 +0300 Subject: [PATCH 11/13] mod2 --- app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index cbd5f51..9958ace 100644 --- a/app.py +++ b/app.py @@ -13,8 +13,8 @@ def hello_world(): # put application's code here def create(): TCI = request.json['chatID'] cursor = db.connection.cursor() - db.query_ins_chat(TCI, curs) - db.close(curs) + db.query_ins_chat(TCI, cursor) + db.close(cursor) @app.route('/start_game') From 701591c38a0d6e43194e88b580a37dc562be7281 Mon Sep 17 00:00:00 2001 From: ada-dmitry Date: Tue, 22 Aug 2023 16:39:10 +0300 Subject: [PATCH 12/13] mod3 --- db.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/db.py b/db.py index cc28068..224649d 100644 --- a/db.py +++ b/db.py @@ -11,12 +11,12 @@ db_params = { connection = psycopg2.connect(**db_params) # запускаем один раз -def query_ins_user(tui, curs=cursor): +def query_ins_user(tui, curs): try: # Запрос добавления пользователя curs.execute( f"""INSERT into public.Users(TrueUserID, role, isAlive) values ({tui}, 0)""") - conn.commit() + connection.commit() except Exception as e: print("Ошибка:", e) @@ -25,7 +25,7 @@ def query_ins_chat(tci, curs=cursor): try: # Запрос добавления чата curs.execute( f"""INSERT into public.Chats(TrueChatID, StateID) values ({tci}, 0)""") - conn.commit() + connection.commit() except Exception as e: print("Ошибка:", e) @@ -48,5 +48,5 @@ def query_change(x): pass -def close(cur=cursor, conn=connection): +def close(cur=cursor, connection=connection): cursor.close() From 71307a1eec77180d468fc12eae79f9bf8faf57c4 Mon Sep 17 00:00:00 2001 From: ada-dmitry Date: Tue, 22 Aug 2023 16:51:47 +0300 Subject: [PATCH 13/13] mod4 --- db.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/db.py b/db.py index 224649d..e8c021a 100644 --- a/db.py +++ b/db.py @@ -21,7 +21,7 @@ def query_ins_user(tui, curs): print("Ошибка:", e) -def query_ins_chat(tci, curs=cursor): +def query_ins_chat(tci, curs): try: # Запрос добавления чата curs.execute( f"""INSERT into public.Chats(TrueChatID, StateID) values ({tci}, 0)""") @@ -30,7 +30,7 @@ def query_ins_chat(tci, curs=cursor): print("Ошибка:", e) -def query_sel(query, curs=cursor): +def query_sel(query, curs): try: # Запрос вывода из БД curs.execute("SELECT * FROM chats") @@ -48,5 +48,5 @@ def query_change(x): pass -def close(cur=cursor, connection=connection): +def close(cur): cursor.close()