-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·58 lines (43 loc) · 1.61 KB
/
main.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
# -*- coding: utf-8 -*-
import logging as log
from timeit import default_timer as timer
from flask import Flask, request
from cron import services
from common import LOG_FORMAT
from secrets import ccn_bot_token
app = Flask(__name__)
@app.before_first_request
def init():
log.basicConfig(level=log.DEBUG, format=LOG_FORMAT)
@app.route('/', methods=['GET'])
def index():
return "CCNBot in funzione.", 200
@app.route('/turn', methods=['GET'])
def turn():
if 'X-Appengine-Cron' in request.headers:
start_time = timer()
code = services.turn()
return f"Richiesta completata in {timer() - start_time} secondi.", code
else:
return "Access restricted to AppEngine-Cron requests.", 403
@app.route('/set_webhook', methods=['GET'])
def wb():
if 'X-Appengine-Cron' in request.headers:
start_time = timer()
code = services.set_webhook()
return f"Richiesta completata in {timer() - start_time} secondi.", code
else:
return "Access restricted to AppEngine-Cron requests.", 403
@app.route('/' + ccn_bot_token, methods=['POST'])
def update():
start_time = timer()
code = services.incoming_update(request)
return f"Richiesta completata in {timer() - start_time} secondi.", code
@app.route('/weekly', methods=['GET'])
def weekly():
if 'X-Appengine-Cron' in request.headers:
start_time = timer()
code = services.weekly()
return f"Richiesta completata in {timer() - start_time} secondi.", code
else:
return "Access restricted to AppEngine-Cron requests.", 403