Skip to content

Commit c576c97

Browse files
Refactoring code
1 parent 2fea0e3 commit c576c97

File tree

5 files changed

+22
-35
lines changed

5 files changed

+22
-35
lines changed

Procfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
web: python wsgi.py
1+
web: python webhook.py
22
init: python manage.py db init
33
migrate: python manage.py db migrate
44
upgrade: python manage.py db upgrade

math_bot/logic.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from telegram import ReplyKeyboardMarkup, KeyboardButton, ReplyKeyboardRemove
22
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, \
33
ConversationHandler
4+
import logging
45

56
from math_bot.app import db
67
from math_bot.tools import send_typing, write_logs, remember_new_user
78
from math_bot.wolfram import make_wolfram_query
89
from math_bot.models import User
9-
from math_bot.error import handle_errors
1010
from config import Config
1111

1212

@@ -362,6 +362,10 @@ def handle_other_messages(bot, update):
362362
return ConversationHandler.END
363363

364364

365+
def handle_errors(bot, update, error):
366+
logging.warning('Update {} caused {} error'.format(update, error))
367+
368+
365369
def init_updater():
366370
updater = Updater(
367371
Config.TELEGRAM_TOKEN,

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ Mako==1.0.7
1616
MarkupSafe==1.0
1717
more-itertools==4.0.1
1818
nginxparser-eb==0.0.9
19+
pkg-resources==0.0.0
1920
psycopg2==2.7.4
2021
pyparsing==2.2.0
2122
python-dateutil==2.6.1
2223
python-editor==1.0.3
23-
python-telegram-bot==9.0.0
24+
python-telegram-bot==10.0.1
2425
requests==2.18.4
2526
six==1.11.0
2627
SQLAlchemy==1.2.4

webhook.py

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,22 @@
1-
from flask import request
2-
from telegram import Update
31
import logging
42
import os
53

6-
from math_bot.app import app
74
from math_bot.logic import init_updater
85
from config import Config
96

107

11-
logging.basicConfig(
12-
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
13-
level=logging.INFO
14-
)
15-
updater = init_updater()
16-
updater.start_webhook(
17-
listen='0.0.0.0',
18-
port=int(os.environ.get('PORT', '8443')),
19-
url_path=Config.TELEGRAM_TOKEN
20-
)
21-
updater.bot.set_webhook(
22-
url='{}/{}'.format(Config.URL, Config.TELEGRAM_TOKEN)
23-
)
24-
updater.idle()
25-
26-
27-
@app.route('/{}'.format(Config.TELEGRAM_TOKEN), methods=['POST'])
28-
def handle_update():
29-
dispatcher = updater.dispatcher
30-
update = Update.de_json(
31-
request.get_json(force=True),
32-
dispatcher.bot
8+
if __name__ == '__main__':
9+
logging.basicConfig(
10+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
11+
level=logging.INFO
12+
)
13+
updater = init_updater()
14+
updater.start_webhook(
15+
listen='0.0.0.0',
16+
port=int(os.environ.get('PORT', '8443')),
17+
url_path=Config.TELEGRAM_TOKEN
18+
)
19+
updater.bot.set_webhook(
20+
url='{}/{}'.format(Config.URL, Config.TELEGRAM_TOKEN)
3321
)
34-
dispatcher.process_update(update)
35-
return 'OK'
22+
updater.idle()

wsgi.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)