Skip to content

Instantly share code, notes, and snippets.

@kmcelwee
Created February 20, 2021 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmcelwee/0b0f09663b91c0d98d9fe0491b543063 to your computer and use it in GitHub Desktop.
Save kmcelwee/0b0f09663b91c0d98d9fe0491b543063 to your computer and use it in GitHub Desktop.
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