-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
45 lines (35 loc) · 1.12 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os
from flask import Flask, request
from pony.orm import db_session
from telegram import Update
from common.utils.db_tools import init_database, get_database
from init import create_bot
ip = os.environ['DFM_WEB_IP']
port = int(os.environ['DFM_WEB_PORT'])
dns = os.environ['DFM_WEB_DNS']
token = os.environ['DFM_BOT_TOKEN']
secret = os.environ['DFM_REQUEST_SECRET']
admin_id = int(os.environ['DFM_ADMIN_ID'])
application = Flask(__name__)
@application.route('/')
def home():
is_up = True
# noinspection PyBroadException
try:
db = get_database()
init_database(db)
with db_session:
if not db.get_connection():
is_up = False
except Exception:
is_up = False
return 'Up.' if is_up else 'Down.'
@application.route('/' + secret, methods=['GET', 'POST'])
def webhook():
if request.json:
update_queue.put(Update.de_json(request.json, bot_instance))
return ''
if __name__ == '__main__':
bot = create_bot(admin_id)
update_queue, bot_instance = bot.run(token, 'https://{}/{}'.format(dns, secret))
application.run(host=ip, port=port)