-
Notifications
You must be signed in to change notification settings - Fork 0
/
flask_app.py
70 lines (51 loc) · 1.97 KB
/
flask_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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!python3
import os
import git
from flask import Flask
from flask import request
from flask import render_template
from flask_sslify import SSLify
from flask_cors import cross_origin
from scripts import github
import telegram
app = Flask(__name__, static_url_path='/static')
app.debug = False
sslify = SSLify(app)
global_context = {}
@app.route('/', methods=['GET'])
def root():
return render_template('root.html', **global_context)
@app.route('/health.php', methods=['GET'])
@cross_origin(origins=['alexandersobyanin.ru'], methods=['GET'])
def health():
return '{"health":1}'
@app.route(telegram.telegram_euc_urals_radio_bot_url, methods=['POST'])
def telegram_euc_urals_radio_bot_webhook():
return telegram.handle_euc_urals_radio_bot(request.get_json())
@app.route(telegram.telegram_euc_urals_pets_bot_url, methods=['POST'])
def telegram_euc_urals_pets_bot_webhook():
return telegram.handle__euc_urals_pets_bot(request.get_json())
@app.route(telegram.telegram_sret_shot_bot_url, methods=['POST'])
def telegram_sret_shot_bot_webhook():
return telegram.handle_sret_shot_bot(request.get_json())
@app.route(telegram.telegram_must_do_it_bot_url, methods=['POST'])
def telegram_must_do_it_bot_webhook():
return telegram.handle_must_do_it_bot(request.get_json())
@app.route('/update_server', methods=['POST'])
def update_server_webhook():
if request.method != 'POST':
return 'Wrong event type', 405
x_hub_signature = request.headers.get('X-Hub-Signature')
if not x_hub_signature:
return 'Wrong params', 402
w_secret = os.getenv('UPDATE_SERVER_WEBHOOK_SECRET_KEY')
if not isinstance(w_secret, str):
return 'Wrong server secret', 403
if not github.is_valid_signature(x_hub_signature, request.data, w_secret):
return 'Access denied', 403
repo = git.Repo('~/mysite/')
origin = repo.remotes.origin
origin.pull()
return 'Updated successfully', 200
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)