-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.py
152 lines (122 loc) · 4.46 KB
/
views.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
from flask import request
from core import *
from flask import jsonify
class InvalidUsage(Exception):
status_code = 400
def __init__(self, message, status_code=None):
Exception.__init__(self)
self.message = message
if status_code is not None:
self.status_code = status_code
def to_dict(self):
return self.message
@app.errorhandler(InvalidUsage)
def handle_invalid_usage(error):
response = jsonify(error.to_dict())
response.status_code = error.status_code
return response
@app.route('/')
def index():
return "Hello world !"
@app.route('/admin', methods=['GET', 'POST'])
def holder_admin():
return admin(request.args, request.form)
@app.route('/manual', methods=['GET'])
def holder_manual():
return manual(request.args)
@app.route('/sync_TDB', methods=['GET'])
def holder_sync_TDB():
r = sync_TDB(request.args)
if isinstance(r, tuple) and isinstance(r[0],int) and isinstance(r[1],str):
raise InvalidUsage(r[1], status_code=r[0])
else:
return r
# @app.route('/sync_Chatfuel', methods=['GET', 'POST'])
# def holder_sync_Chatfuel():
# return sync_Chatfuel(request.args, request.json)
@app.route('/cron_call', methods=['GET'])
def holder_cron_call():
r = cron_call(request.args)
if isinstance(r, tuple) and isinstance(r[0],int) and isinstance(r[1],str):
raise InvalidUsage(r[1], status_code=r[0])
else:
return r
@app.route('/liste_joueurs', methods=['GET'])
def holder_liste_joueurs():
return liste_joueurs(request.args)
@app.route('/choix_cible', methods=['GET', 'POST'])
def holder_choix_cible():
return choix_cible(request.args, request.json, request.url_root)
@app.route('/envoi_mp', methods=['GET', 'POST'])
def holder_envoi_mp():
r = envoi_mp(request.args, request.json)
if isinstance(r, tuple) and isinstance(r[0],int) and isinstance(r[1],str):
raise InvalidUsage(r[1], status_code=r[0])
else:
return r
@app.route('/media_renderer', methods=['GET', 'POST'])
def holder_media_renderer():
return media_renderer(request.args, request.json)
@app.route('/API_test', methods=['GET', 'POST'])
def holder_API_test():
return API_test(request.args, request.json)
@app.route('/Hermes_test', methods=['GET'])
def holder_Hermes_test():
return Hermes_test(request.args)
#
# @app.route('/testbot', methods=['GET', 'POST'])
# def holder_testbot():
# ACCESS_TOKEN="EAAKfdOGXd00BAIiZAZBV6ha7fHO4veDz3wMKD8yGZAlALqG0S4FZCZBPrcloFrICqCq9D7C0DwSgyGmRDgycSsaHrvpP8TJtyT1xEf71ZCJSzPpM5mcf5DDBmJUcEo98OBoWWBP8URGopJ88CZBkEPlZAKRbWhbBqGjMoggNR633sWGb3SsuaZAKZB"
#
# log = ""
#
# m = request.method
# a = request.args
# f = request.form
# j = request.json
# d = request.data
#
# if "hub.challenge" in a:
# rep = d["hub.challenge"]
# else:
# rep = 'rep'
#
# log += f"> {time.ctime()} : appel testbot\nrequest:{request}json:{j}\n"
# # log += f"> {time.ctime()} : appel testbot\nrequest:{request}\nmethod:{m}\nargs:{a}\nform:{f}\njson:{j}\ndata:{d}\nrep:{rep}\n\n"
#
# # Handles messages events
# def handleMessage(sender_psid, received_message, log):
# log += f"\nMessage: id:{sender_psid}, message:{received_message}\n"
# log = callSendAPI(sender_psid, received_message.upper(), log)
#
# return log
#
# # Handles messaging_postbacks events
# def handlePostback(sender_psid, received_postback):
# pass
#
# # Sends response messages via the Send API
# def callSendAPI(sender_psid, response, log):
# params = {"access_token": ACCESS_TOKEN}
# request_body = {
# "recipient": {"id": sender_psid},
# "message": {"text": response},
# }
# log += f"Answer: {request_body}\n\n"
# rep = requests.post("https://graph.facebook.com/v2.6/me/messages", params=params, json=request_body)
#
# log += rep.text
# return log
#
#
# if "entry" in j:
# entry = j["entry"][0]
# if "messaging" in entry:
# messaging = entry["messaging"][0]
# if "sender" in messaging and "message" in messaging:
# id = messaging["sender"]["id"]
# message = messaging["message"]["text"]
# log = handleMessage(id, message, log)
#
# with open(f"logs/testbot/{time.strftime('%Y-%m-%d')}.log", 'a+') as fich:
# fich.write(log+"\n\n")