Store received messages instead of updates

This commit is contained in:
bursa-pastoris 2023-10-13 18:34:56 +02:00
parent d45833cb6e
commit 42d34d59c8
2 changed files with 4 additions and 3 deletions

View File

@ -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']}

View File

@ -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: