From 7c67f2f5bdfa80bdb545d5ea6c2c239d83838f81 Mon Sep 17 00:00:00 2001 From: Lulzette Date: Tue, 7 Sep 2021 07:29:43 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D1=8C=20=D1=80=D0=B5=D0=B4=D0=B0=D0=BA=D1=82=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BE=D1=81=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BD=D0=BE=D0=B9=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86?= =?UTF-8?q?=D1=8B=20(=D1=85=D0=BE=D1=82=D1=8F=20=D0=B2=D1=80=D1=8F=D0=B4?= =?UTF-8?q?=20=D0=BB=D0=B8=20=D1=81=D1=82=D0=BE=D0=B8=D1=82=20=D1=82=D0=B0?= =?UTF-8?q?=D0=BA=20=D0=B4=D0=B5=D0=BB=D0=B0=D1=82=D1=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/main.py b/main.py index 5db80eb..99d29a6 100755 --- a/main.py +++ b/main.py @@ -60,6 +60,20 @@ def index(): except TypeError: return abort(404, 'No such page') +@route('/', method='POST') +def post(): + ''' + Insert/Update post + ''' + body = request.forms.get('body') + # If post exists, update it + if posts.find_one({'name': '/'}): + newPost = {'$set': {'text': body}} + return str(posts.update_one({'name': '/'}, newPost)) + # Else - create new + else: + newPost = {'name': '/', 'text': body} + return str(posts.insert_one(newPost).inserted_id) if __name__ == '__main__': run(host='0.0.0.0', port=8081, reloader=True, debug=True)