42 lines
1.4 KiB
Python
Executable File
42 lines
1.4 KiB
Python
Executable File
#!/bin/env python3
|
|
|
|
# scel-buc - scripts to send and receive messages through a Telegram bot
|
|
# Copyright (C) 2023 bursa-pastoris
|
|
#
|
|
# This file is part of scel-buc.
|
|
#
|
|
# scel-buc is free software: you can redistribute it and/or modify it under the
|
|
# terms of the GNU Affero General Public License as published by the Free
|
|
# Software Foundation, version 3 of the License.
|
|
#
|
|
# scel-buc is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
# details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with scel-buc. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
import urllib.request
|
|
import json
|
|
from datetime import datetime as dt
|
|
|
|
from constants import *
|
|
|
|
|
|
def get_updates(offset=0):
|
|
try:
|
|
with urllib.request.urlopen(f'{API}/getUpdates?offset={offset}') as request:
|
|
updates = json.loads(request.read())
|
|
with open(MESSAGES, 'a') as f:
|
|
for i in updates['result']:
|
|
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:
|
|
print('Maybe you are using an invalid token?')
|
|
|
|
if __name__ == '__main__':
|
|
get_updates()
|