|
|
@@ -49,8 +49,7 @@ class MediaStreamListener(tweepy.StreamListener): |
|
|
|
pass |
|
|
|
video_urls.append(best_url) |
|
|
|
|
|
|
|
# Go through and download everything, and optionally delete the tweet |
|
|
|
# after downloading. |
|
|
|
# Go through and download everything |
|
|
|
for url in photo_urls + video_urls: |
|
|
|
fname = url.split("/")[-1].split("?")[0] |
|
|
|
r = requests.get(url, stream=True) |
|
|
@@ -59,13 +58,14 @@ class MediaStreamListener(tweepy.StreamListener): |
|
|
|
with open(path.join(config["output_dir"], fname), 'wb') as outfile: |
|
|
|
r.raw.decode_content = True |
|
|
|
shutil.copyfileobj(r.raw, outfile) |
|
|
|
|
|
|
|
if config["burn_after_reading"]: |
|
|
|
api.destroy_status(status.id) |
|
|
|
print(f"Tweet {status.id} deleted.") |
|
|
|
else: |
|
|
|
print(f"Whoops. Something went wrong downloading {fname}") |
|
|
|
|
|
|
|
# Optionally delete the tweet after doing the downloading |
|
|
|
if config["burn_after_reading"]: |
|
|
|
api.destroy_status(status.id) |
|
|
|
print(f"Tweet {status.id} deleted.") |
|
|
|
|
|
|
|
|
|
|
|
listener = MediaStreamListener() |
|
|
|
stream = tweepy.Stream(auth=auth, listener=listener) |