diff --git a/filler.py b/filler.py index 1c69e52..d9ce7e9 100755 --- a/filler.py +++ b/filler.py @@ -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