From 42d34d59c80758c4e1e52dedf460ec7b369599a8 Mon Sep 17 00:00:00 2001 From: bursa-pastoris Date: Fri, 13 Oct 2023 18:34:56 +0200 Subject: [PATCH] Store received messages instead of updates --- constants.py | 2 +- scel-buc.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/constants.py b/constants.py index 9aab3ff..38c8555 100644 --- a/constants.py +++ b/constants.py @@ -37,7 +37,7 @@ with open('.last_msg','r') as f: API = f'https://api.telegram.org/bot{TOKEN}' -UPDATES = CHAT_PATH+'updates.json' +MESSAGES = CHAT_PATH+'messages.json' USER_NAMES = {i:config['users'][i] for i in config['users']} GROUP_NAMES = {i:config['groups'][i] for i in config['groups']} diff --git a/scel-buc.py b/scel-buc.py index af6fd0e..99ebaa9 100755 --- a/scel-buc.py +++ b/scel-buc.py @@ -28,9 +28,10 @@ def get_updates(offset=0): try: with urllib.request.urlopen(f'{API}/getUpdates?offset={offset}') as request: updates = json.loads(request.read()) - with open(UPDATES, 'a') as f: + with open(MESSAGES, 'a') as f: for i in updates['result']: - f.write(json.dumps(i, indent=4)+'\n') + if 'message' in i: + f.write(json.dumps(i['message'], indent=4)+'\n') except urllib.error.HTTPError as e: print(f'HTTP error {e.code}: {e.reason}') if e.code == 401: