-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbotan.py
36 lines (31 loc) · 1.06 KB
/
botan.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
# -*- coding: utf-8 -*-
# Taken from here https://github.com/MasterGroosha/telegram-tutorial/blob/master/lesson_06/botan.py
import requests
import json
TRACK_URL = 'https://api.botan.io/track'
def make_json(message):
data = {}
data['message_id'] = message.message_id
data['from'] = {}
data['from']['id'] = message.from_user.id
if message.from_user.username is not None:
data['from']['username'] = message.from_user.username
data['chat'] = {}
data['chat']['id'] = message.chat.id
return data
def track(token, uid, message, name='Message'):
try:
r = requests.post(
TRACK_URL,
params={"token": token, "uid": uid, "name": name},
data=make_json(message),
headers={'Content-type': 'application/json'},
)
return r.json()
except requests.exceptions.Timeout:
# set up for a retry, or continue in a retry loop
return False
except (requests.exceptions.RequestException, ValueError) as e:
# catastrophic error
print(e)
return False