From e0e687e1ce8146c7ef790b0f4e93083a1662c84f Mon Sep 17 00:00:00 2001 From: Jacob Casper Date: Fri, 3 Apr 2020 01:20:39 -0500 Subject: [PATCH] Write media URLs to database, not media to disk --- mms-download.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/mms-download.py b/mms-download.py index 86c2a3d..eb03ae3 100644 --- a/mms-download.py +++ b/mms-download.py @@ -1,5 +1,5 @@ import os -import requests +import sqlite3 from flask import Flask, request from twilio.twiml.messaging_response import MessagingResponse @@ -8,12 +8,17 @@ app = Flask(__name__) @app.route("/mms", methods=['POST']) def sms_reply(): """Respond to incoming multimedia messages with a confirmed download text.""" + sender = request.form['From'] if request.form['NumMedia'] is not None: urls = [request.form['MediaUrl' + str(idx)] for idx in range(int(request.form['NumMedia']))] - photos = {url.split("/")[-1]: requests.get(url) for url in urls} - for identifier, photo in photos.items(): - with open(identifier + '.jpg', 'wb') as f: - f.write(photo.content) + + conn = sqlite3.connect("mercuryms.sqlite") + cursor = conn.cursor() + for url in urls: + cursor.execute('INSERT INTO MEDIA (PHONE_NUMBER, URI) VALUES (?, ?)', (sender, url)) + conn.commit() + conn.close() + resp = MessagingResponse() resp.message("Upload received!") return str(resp) -- 2.20.1