Added 10 more gists.
This commit is contained in:
1
tweets.py/README.md
Normal file
1
tweets.py/README.md
Normal file
@@ -0,0 +1 @@
|
||||
Python script to fetch images from a Twitter account.
|
||||
33
tweets.py/tweets.py
Normal file
33
tweets.py/tweets.py
Normal 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
|
||||
Reference in New Issue
Block a user