Implement media download in filler
This commit is contained in:
parent
75c9304bac
commit
c015769950
1 changed files with 8 additions and 2 deletions
10
filler.py
10
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
|
||||
|
|
Loading…
Reference in a new issue