Skip to content

Commit

Permalink
Merge 29f5b73 into c9bc5cc
Browse files Browse the repository at this point in the history
  • Loading branch information
Xevib committed Aug 19, 2020
2 parents c9bc5cc + 29f5b73 commit 6d9b8e7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions .travis.yml
@@ -1,6 +1,7 @@
language: python
python:
- "2.7"
- "3.8"
before_script:
- psql -c 'create database bot;' -U postgres
- psql -c 'CREATE TABLE users (id int, mode varchar(30),zoom int,format varchar(30),language varchar(10))' -U postgres
Expand Down
10 changes: 8 additions & 2 deletions bot/osmbot_blueprint.py
Expand Up @@ -11,6 +11,7 @@
from bot.osmbot import OsmBot
from telegram import Bot as TBot
from telegram import error
import sys

application = Flask(__name__)
application.debug = True
Expand Down Expand Up @@ -91,8 +92,13 @@ def attend_webhook(token):
except error.Unauthorized:
return 'OK'
except Exception as e:
if e.message == 'Unauthorized':
return 'OK'
if sys.version_info.major ==2:
if e.message == 'Unauthorized':
return 'OK'
else:
if str(e) == 'Unauthorized':
return 'OK'

print(str(e))
import traceback
traceback.print_exc()
Expand Down
6 changes: 5 additions & 1 deletion bot/user.py
@@ -1,6 +1,7 @@
import psycopg2
from psycopg2.extras import DictCursor
from hashlib import sha1
import sys


def dict_factory(cursor, row):
Expand Down Expand Up @@ -55,7 +56,10 @@ def get_user(self, identifier, group=False):
:param group:
:return:
"""
shaid = sha1(str(identifier)).hexdigest()
if sys.version_info.major ==2:
shaid = sha1(str(identifier)).hexdigest()
else:
shaid = sha1(str(identifier).encode("utf-8")).hexdigest()
cur = self.conn.cursor(cursor_factory=DictCursor)
if group:
sql = 'SELECT * FROM groups WHERE shaid = %s LIMIT 1'
Expand Down
8 changes: 6 additions & 2 deletions test/test.py
Expand Up @@ -6,7 +6,8 @@
from six.moves import reload_module
import sys
reload_module(sys)
sys.setdefaultencoding('utf-8')
if sys.version_info.major ==2:
sys.setdefaultencoding('utf-8')

from bot.osmbot import OsmBot
from bot.error import OSMError
Expand Down Expand Up @@ -94,7 +95,10 @@ def test_templates(self):
for template in templates:
print('Testing template:{}'.format(template))
with open(os.path.join('bot/templates', template)) as f:
template_text = unicode(f.read())
if sys.version_info.major == 2:
template_text = unicode(f.read())
else:
template_text = f.read()
try:
jinja_env.from_string(template_text).render()
except exceptions.TemplateAssertionError:
Expand Down

0 comments on commit 6d9b8e7

Please sign in to comment.