From 45890fd1032064b30d181f5811f8be5516b0776b Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Mon, 27 Feb 2017 00:39:34 +0100 Subject: [PATCH] Add file downloader to filler --- filler.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/filler.py b/filler.py index 999c893..1c69e52 100755 --- a/filler.py +++ b/filler.py @@ -1,6 +1,16 @@ #!/usr/bin/env python3 -import argparse, dbtools, dbtools.fillerfilter, setuptools, time, twitools +import argparse, dbtools, dbtools.fillerfilter, requests, setuptools, time, twitools + +def downloadMedia(url, tid, mid): + remote = requests.get(url, stream=True) + filename = "media/%i_%i.%s" % (tid, mid, url.split(".")[-1]) + + with open(filename, 'wb') as outfile: + for chunk in remote.iter_content(chunk_size=1024): + if chunk: + outfile.write(chunk) + outfile.flush() def getTweets(db=dbtools.dbHelper(), user=twitools.twObject().whoami(), two=twitools.twObject()): query = "from:" + user