Implement media download in filler

This commit is contained in:
Klaus-Uwe Mitterer 2017-02-27 00:44:50 +01:00
parent 75c9304bac
commit c015769950

View file

@ -4,7 +4,7 @@ import argparse, dbtools, dbtools.fillerfilter, requests, setuptools, time, twit
def downloadMedia(url, tid, mid):
remote = requests.get(url, stream=True)
filename = "media/%i_%i.%s" % (tid, mid, url.split(".")[-1])
filename = "media/%i_%i.%s" % (int(tid), int(mid), url.split(".")[-1])
with open(filename, 'wb') as outfile:
for chunk in remote.iter_content(chunk_size=1024):
@ -29,7 +29,13 @@ def getTweets(db=dbtools.dbHelper(), user=twitools.twObject().whoami(), two=twit
try:
db.executeQuery("INSERT INTO tweets(tweet_id,timestamp,text) VALUES(" + str(status.id) + ",'" + timestamp + "','" + text + "')")
except:
pass
print("Failed to insert %s into database." % str(status.id))
if 'media' in status.entities:
mid = 0
for m in status.entities['media']:
downloadMedia(m['media_url'], status.id, mid)
mid += 1
last = status.id
tw_counter = tw_counter + 1