-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
35 lines (25 loc) · 850 Bytes
/
app.py
File metadata and controls
35 lines (25 loc) · 850 Bytes
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
import os
import json
from flask import Flask, request
from signature import validate_signature
app = Flask(__name__)
app.config.from_pyfile('app.cfg')
@app.route('/', methods=['GET'])
def ping():
return 'OK'
@app.route('/hook', methods=['POST'])
def hook():
validate_signature(request, app.config.get('KEYS'), app.config.get('HOST'))
event = json.loads(request.data)
eventid = event["EventId"]
eventtype = event["EventType"]
payload = event['Payload']
print("event: {}, id: {}".format(eventtype, eventid))
datadir = app.config.get('DATADIR')
os.makedirs(datadir, exist_ok=True)
filepath = '{}/{}_{}.json'.format(datadir, eventid, eventtype)
with open(filepath, mode='w', encoding='utf8') as f:
json.dump(payload, f, indent=' ')
return 'POST'
if __name__ == '__main__':
app.run()