-
Notifications
You must be signed in to change notification settings - Fork 0
/
lookupFriendship.py
73 lines (57 loc) · 1.73 KB
/
lookupFriendship.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import json
import csv
from pymongo import MongoClient
from twython import Twython
from twython import Twython,TwythonError,TwythonRateLimitError
import time
import threading
consumer_key = "mIj80gaFYc0jhob7cFx5yCXR7"
consumer_secret = "5qF1SAiuFszHMbXNLhBZkO40bv1GEOz4pyj2xIBimSwaWvriow"
access_token = "243047872-aecR8MeWtZBTaaF8UFXqSWrqHrRdrd14Z3GFffqx"
access_token_secret = "wTS5LBz0fWST7lgo7KRtThgbAntFS0NLOuCN8guBcxcFD"
twitter = Twython(consumer_key,consumer_secret,access_token,access_token_secret)
tweetID = '685195966731816960'
file = tweetID +'.txt'
followersFile = tweetID + '.RTS_FriendshipLookup.txt'
tweeter = ""
tweeterID = ""
threads = []
retweeters = []
trt = {}
def lookupTweet(id):
tweet = twitter.lookup_status(id=tweetID)
tw = tweet[0]
global tweeter
global tweeterID
tweeter = tw['user']['screen_name']
tweeterID = tw['user']['id_str']
def fetchRetweeters():
with open(file) as rts:
for rt in rts:
if (len(rt) > 0):
retweeters.append(rt.strip())
def lookup(source,target):
i=0
follows = []
while i < len(target):
j=1
while j<= 15 & i<len(target):
friendship = twitter.show_friendship(source_id=source,target_id=target[i])
if friendship['relationship']['source']['followed_by'] == True:
follows.append(target[i])
else:
pass
i=i+1
j=j+1
time.sleep(900)
trt[source]=follows
print(follows)
if __name__ == '__main__':
lookupTweet(tweetID)
fetchRetweeters()
try:
lookup(tweeterID,retweeters)
except (TwythonError,TwythonRateLimitError) as te:
pass
with open(followersFile, 'a') as ff:
print(trt, file=ff)