-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrello_listener.py
33 lines (27 loc) · 943 Bytes
/
trello_listener.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
from card_descriptor import set_description
from extractor import extract_infos_from_pdf
from flask import Flask
from flask import abort
from flask import request
from link_builder import get_wpp_url
from url_shortner import shorten_url
app = Flask(__name__)
@app.route('/listen', methods=['GET', 'POST'])
def listener():
if request.method == 'GET':
return 'OK, foi um GET', 200
if request.method == 'HEAD':
return '', 200
if request.method == 'POST':
if request.json['action']['type'] == 'addAttachmentToCard':
card_id = request.json['action']['data']['card']['id']
pdf_url = request.json['action']['data']['attachment']['url']
pdf_info = extract_infos_from_pdf(pdf_url)
wpp_url = get_zap_link(pdf_info)
set_description(card_id, shortened_wpp_url)
else:
print('POST DIFERENTE')
print(request.json)
return '', 200
if __name__ == '__main__':
app.run(debug=True)