-
Notifications
You must be signed in to change notification settings - Fork 0
/
python_script.py
42 lines (28 loc) · 1.06 KB
/
python_script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import requests
url = "https://api.telegram.org/bot514193432:AAHI910wcfgiRPiD8f1NyiOFkJ5I_-of870/"
def get_updates_json(request):
params = {'timeout': 100, 'offset': None}
response = requests.get(request + 'getUpdates', data=params)
return response.json()
def last_update(data):
results = data['result']
total_updates = len(results) - 1
return results[total_updates]
def get_chat_id(update):
chat_id = update['message']['chat']['id']
return chat_id
def send_mess(chat, text):
params = {'chat_id': chat, 'text': text}
response = requests.post(url + 'sendMessage', data=params)
return response
chat_id = get_chat_id(last_update(get_updates_json(url)))
send_mess(chat_id, 'You're doing ok!')
def main():
update_id = last_update(get_updates_json(url))['update_id']
while True:
if update_id == last_update(get_updates_json(url))['update_id']:
send_mess(get_chat_id(last_update(get_updates_json(url))), 'test')
update_id += 1
sleep(3)
if __name__ == '__main__':
main()