Created
February 20, 2021 00:09
-
-
Save kmcelwee/0b0f09663b91c0d98d9fe0491b543063 to your computer and use it in GitHub Desktop.
Download images (JPG, PNG) from tweets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import wget | |
from os.path import join as pjoin | |
OUTPUT_DIR = 'tweet-imgs' | |
media_tweets = [tweet for tweet in tweets if 'media' in tweet['entities']] | |
for tweet in media_tweets: | |
for i, media in enumerate(tweet['entities']['media']): | |
url = media['media_url'] | |
extension = url.split('.')[-1] | |
assert extension in ['jpg', 'png'] | |
output_file = f"{tweet['user']['name']}-{tweet['id']}-{i}.{extension}" | |
wget.download(url, out=pjoin(OUTPUT_DIR, output_file)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment