Skip to content

Commit f31bd91

Browse files
committed
Merge pull request python-telegram-bot#305 from python-telegram-bot/move-botan
move botan from utils to contrib
2 parents 32ac617 + b06983a commit f31bd91

File tree

5 files changed

+58
-53
lines changed

5 files changed

+58
-53
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
telegram.contrib.botan module
2+
=============================
3+
4+
.. automodule:: telegram.contrib.botan
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

telegram/contrib/__init__.py

Whitespace-only changes.

telegram/contrib/botan.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import logging
2+
from telegram import NullHandler
3+
4+
from future.moves.urllib.parse import quote
5+
from future.moves.urllib.error import HTTPError, URLError
6+
from future.moves.urllib.request import urlopen, Request
7+
8+
logging.getLogger(__name__).addHandler(NullHandler())
9+
10+
11+
class Botan(object):
12+
"""This class helps to send incoming events to your botan analytics account.
13+
See more: https://github.com/botanio/sdk#botan-sdk
14+
"""
15+
16+
token = ''
17+
url_template = 'https://api.botan.io/track?token={token}' \
18+
'&uid={uid}&name={name}&src=python-telegram-bot'
19+
20+
def __init__(self, token):
21+
self.token = token
22+
self.logger = logging.getLogger(__name__)
23+
24+
def track(self, message, event_name='event'):
25+
try:
26+
uid = message.chat_id
27+
except AttributeError:
28+
self.logger.warn('No chat_id in message')
29+
return False
30+
data = message.to_json()
31+
try:
32+
url = self.url_template.format(token=str(self.token),
33+
uid=str(uid),
34+
name=quote(event_name))
35+
request = Request(url,
36+
data=data.encode(),
37+
headers={'Content-Type': 'application/json'})
38+
urlopen(request)
39+
return True
40+
except HTTPError as error:
41+
self.logger.warn('Botan track error ' + str(error.code) + ':' + error.read().decode(
42+
'utf-8'))
43+
return False
44+
except URLError as error:
45+
self.logger.warn('Botan track error ' + str(error.reason))
46+
return False

telegram/utils/botan.py

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,4 @@
1-
#!/usr/bin/env python
1+
from .deprecate import deprecate
2+
from telegram.contrib.botan import Botan as Bo
23

3-
import logging
4-
from telegram import NullHandler
5-
6-
try:
7-
from urllib.request import urlopen, Request
8-
from urllib.parse import quote
9-
from urllib.error import URLError, HTTPError
10-
except ImportError:
11-
from urllib2 import urlopen, Request
12-
from urllib import quote
13-
from urllib2 import URLError, HTTPError
14-
15-
logging.getLogger(__name__).addHandler(NullHandler())
16-
17-
18-
class Botan(object):
19-
"""This class helps to send incoming events in your botan analytics account.
20-
See more: https://github.com/botanio/sdk#botan-sdk"""
21-
22-
token = ''
23-
url_template = 'https://api.botan.io/track?token={token}' \
24-
'&uid={uid}&name={name}&src=python-telegram-bot'
25-
26-
def __init__(self, token):
27-
self.token = token
28-
self.logger = logging.getLogger(__name__)
29-
30-
def track(self, message, event_name='event'):
31-
try:
32-
uid = message.chat_id
33-
except AttributeError:
34-
self.logger.warn('No chat_id in message')
35-
return False
36-
data = message.to_json()
37-
try:
38-
url = self.url_template.format(token=str(self.token),
39-
uid=str(uid),
40-
name=quote(event_name))
41-
request = Request(url,
42-
data=data.encode(),
43-
headers={'Content-Type': 'application/json'})
44-
urlopen(request)
45-
return True
46-
except HTTPError as error:
47-
self.logger.warn('Botan track error ' + str(error.code) + ':' + error.read().decode(
48-
'utf-8'))
49-
return False
50-
except URLError as error:
51-
self.logger.warn('Botan track error ' + str(error.reason))
52-
return False
4+
Botan = deprecate(Bo, 'telegram.utils.botan', 'telegram.contrib.botan')

tests/test_botan.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
"""This module contains a object that represents Tests for Botan analytics integration"""
2+
"""This module contains an object that represents Tests for Botan analytics integration"""
33

44
import sys
55
import unittest
@@ -9,7 +9,7 @@
99

1010
sys.path.append('.')
1111

12-
from telegram.utils.botan import Botan
12+
from telegram.contrib.botan import Botan
1313
from tests.base import BaseTest
1414

1515

0 commit comments

Comments
 (0)