-
Notifications
You must be signed in to change notification settings - Fork 323
/
twitter-list-retweets.py
executable file
·45 lines (36 loc) · 1.81 KB
/
twitter-list-retweets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
#-----------------------------------------------------------------------
# twitter-retweets
# - print who has retweeted tweets from a given user's timeline
#-----------------------------------------------------------------------
from twitter import *
user = "ideoforms"
#-----------------------------------------------------------------------
# load our API credentials
#-----------------------------------------------------------------------
import sys
sys.path.append(".")
import config
#-----------------------------------------------------------------------
# create twitter API object
#-----------------------------------------------------------------------
twitter = Twitter(auth=OAuth(config.access_key,
config.access_secret,
config.consumer_key,
config.consumer_secret))
#-----------------------------------------------------------------------
# perform a basic search
# twitter API docs: https://dev.twitter.com/rest/reference/get/statuses/user_timeline
#-----------------------------------------------------------------------
results = twitter.statuses.user_timeline(screen_name=user)
#-----------------------------------------------------------------------
# loop through each of my statuses, and print its content
#-----------------------------------------------------------------------
for status in results:
print("@%s %s" % (user, status["text"]))
#-----------------------------------------------------------------------
# do a new query: who has RT'd this tweet?
#-----------------------------------------------------------------------
retweets = twitter.statuses.retweets._id(_id=status["id"])
for retweet in retweets:
print(" - retweeted by %s" % (retweet["user"]["screen_name"]))