mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-23 06:50:29 +01:00
Remove Botan (#776)
This commit is contained in:
parent
8cda3f7a71
commit
160ffed5ad
2 changed files with 0 additions and 46 deletions
|
@ -1,3 +0,0 @@
|
|||
from .botan import Botan
|
||||
|
||||
__all__ = ['Botan']
|
|
@ -1,43 +0,0 @@
|
|||
import logging
|
||||
|
||||
from future.moves.urllib.parse import quote
|
||||
from future.moves.urllib.error import HTTPError, URLError
|
||||
from future.moves.urllib.request import urlopen, Request
|
||||
|
||||
logging.getLogger(__name__).addHandler(logging.NullHandler())
|
||||
|
||||
|
||||
class Botan(object):
|
||||
"""This class helps to send incoming events to your botan analytics account.
|
||||
See more: https://github.com/botanio/sdk#botan-sdk
|
||||
"""
|
||||
|
||||
token = ''
|
||||
url_template = 'https://api.botan.io/track?token={token}' \
|
||||
'&uid={uid}&name={name}&src=python-telegram-bot'
|
||||
|
||||
def __init__(self, token):
|
||||
self.token = token
|
||||
self.logger = logging.getLogger(__name__)
|
||||
|
||||
def track(self, message, event_name='event'):
|
||||
try:
|
||||
uid = message.chat_id
|
||||
except AttributeError:
|
||||
self.logger.warn('No chat_id in message')
|
||||
return False
|
||||
data = message.to_json()
|
||||
try:
|
||||
url = self.url_template.format(
|
||||
token=str(self.token), uid=str(uid), name=quote(event_name))
|
||||
request = Request(
|
||||
url, data=data.encode(), headers={'Content-Type': 'application/json'})
|
||||
urlopen(request)
|
||||
return True
|
||||
except HTTPError as error:
|
||||
self.logger.warn('Botan track error ' + str(error.code) + ':' + error.read().decode(
|
||||
'utf-8'))
|
||||
return False
|
||||
except URLError as error:
|
||||
self.logger.warn('Botan track error ' + str(error.reason))
|
||||
return False
|
Loading…
Reference in a new issue