-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.py
executable file
·52 lines (41 loc) · 1.38 KB
/
server.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
from flask import Flask, request, send_from_directory
from threading import Thread
from conf import VERIFY_TOKEN
import core
# Instanciation du serveur web
webserver = Flask(__name__)
# Instanciation du principal execution
traitement = core.Traitement()
@webserver.route("/", methods=["GET", "POST"])
def receive_message():
if request.method == "GET":
'''
Ce cas est destiné au verification de l'etat de
vie du serveur web, utilise par Facebook pour
justifier que ce serveur reçoit les messages envoyés.
'''
token_sent = request.args.get("hub.verify_token")
if token_sent == VERIFY_TOKEN:
return request.args.get("hub.challenge")
return "Invalid verification token"
elif request.method == "POST":
'''
Les requetes envoyés en moode 'POST' sont les messages
envoyé sur la page Facebook et qui sont à traiter.
'''
body = request.get_json()
proc = Thread(target=traitement._analyse, args=[body])
proc.start()
return "receive", 200
@webserver.route("/<filename>")
def get_file(filename):
try:
return send_from_directory(
'./photo/',
path=filename,
as_attachment=True
)
except FileNotFoundError:
abort(404)
if __name__ == "__main__":
webserver.run(debug=True, port=7000)