Commit | Line | Data |
---|---|---|
dfab08b8 JC |
1 | import requests |
2 | from flask import Flask, request | |
3 | from twilio.twiml.messaging_response import MessagingResponse | |
4 | ||
5 | app = Flask(__name__) | |
6 | ||
7 | @app.route("/mms", methods=['POST']) | |
8 | def sms_reply(): | |
9 | """Respond to incoming multimedia messages with a confirmed download text.""" | |
10 | if request.form['NumMedia'] is not None: | |
11 | urls = [request.form['MediaUrl' + str(idx)] for idx in range(int(request.form['NumMedia']))] | |
12 | photos = {url.split("/")[-1]: requests.get(url) for url in urls} | |
13 | for identifier, photo in photos.items(): | |
14 | with open(identifier + '.jpg', 'wb') as f: | |
15 | f.write(photo.content) | |
16 | resp = MessagingResponse() | |
17 | resp.message("Upload received!") | |
18 | return str(resp) | |
19 | ||
20 | if __name__ == '__main__': | |
21 | app.run(host='0.0.0.0', port=9092, debug=True) |