Files
Gists/tweets.py/tweets.py
2023-06-20 22:03:49 -04:00

33 lines
908 B
Python

#! /usr/bin/python
import tweepy
import requests
import urllib2
CONSUMER_KEY = ""
CONSUMER_SECRET = ""
OAUTH_TOKEN = ""
OAUTH_SECRET = ""
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(OAUTH_TOKEN, OAUTH_SECRET)
api = tweepy.API(auth)
timeline = api.user_timeline(count = 1000, screen_name = "")
img_count = 0
for tweet in timeline:
# Iterate over media entities
for media in tweet.entities.get("media",[{}]):
# Check if the media is an image
if media.get("type", None) == "photo":
# Request media file
print(media["media_url"])
req = urllib2.Request(media["media_url"])
rsp = urllib2.urlopen(req)
file_name = "imgs/image%03d.jpg" % img_count
# Save the image file
with open(file_name, "w") as f:
f.write(rsp.read())
img_count += 1