-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbotan.py
46 lines (40 loc) · 1.12 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
37
38
39
40
41
42
43
44
45
46
# ----------------
# dont forget 'pip install requests' first
# ----------------
# usage example:
#
# import botan
#
# print botan.track(1111, 1, {'text':2}, 'Search')
import requests
import json
TRACK_URL = 'https://api.botan.io/track'
SHORTENER_URL = 'https://api.botan.io/s/'
def track(token, uid, message, name='Message'):
try:
r = requests.post(
TRACK_URL,
params={"token": token, "uid": uid, "name": name},
data=json.dumps(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
def shorten_url(url, botan_token, user_id):
"""
Shorten URL for specified user of a bot
"""
try:
return requests.get(SHORTENER_URL, params={
'token': botan_token,
'url': url,
'user_ids': str(user_id),
}).text
except:
return url