Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Download images (JPG, PNG) from tweets
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