Added 10 more gists.

This commit is contained in:
Miguel Astor
2023-06-20 22:03:49 -04:00
parent 1400a87eab
commit 22ff5bfa25
19 changed files with 1642 additions and 0 deletions

1
tweets.py/README.md Normal file
View File

@@ -0,0 +1 @@
Python script to fetch images from a Twitter account.

33
tweets.py/tweets.py Normal file
View File

@@ -0,0 +1,33 @@
#! /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