This repository has been archived by the owner on Nov 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8e9c41
commit 36ab81a
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# ---------------- | ||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import botan | ||
import config | ||
|
||
tkn = None | ||
|
||
if hasattr(config, 'BOTANIO_TOKEN'): | ||
tkn = config.BOTANIO_TOKEN | ||
|
||
def track(uid, message, name='Message'): | ||
if tkn is not None: | ||
botan.track(tkn, uid, message, name) | ||
|