forked from Ahsan196/FYP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheck_Retweet_Count_and_saving_retweeter_IDs.py
More file actions
65 lines (62 loc) · 3.25 KB
/
Check_Retweet_Count_and_saving_retweeter_IDs.py
File metadata and controls
65 lines (62 loc) · 3.25 KB
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
import time
import json
consumer_key=""
consumer_secret=""
access_key=""
access_secret=""
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth,wait_on_rate_limit=True,wait_on_rate_limit_notify=True)
a=[]
with open("path/any.txt",'r') as fle:
for item in fle:
try:
a=api.retweeters(item)
print("Retweeters of " +item)
print(a)
except tweepy.TweepError as ex:
if ex.reason == "Sorry, that page does not exist.":
with open("path/notexist.txt","a") as fol:
fol.write(item)
fol.write("\n")
if len(a) > 0 and len(a) <=10:
with open('path/reaTweet_IDs_having_retweets_counts_1-10.txt','a', encoding='utf8') as fi:
fi.write(item)
fi.write("\n")
with open('path/realRetweeters of tweet %s.txt' %item.strip(),'a', encoding='utf8') as flei:
for it in a:
flei.write(str(it))
flei.write("\n")
if len(a) > 10 and len(a) <=20:
with open('path/realTweet_IDs_having_retweets_counts_11-20.txt','a', encoding='utf8') as fie:
fie.write(item)
fie.write("\n")
with open('path/realRetweeters of tweet %s.txt' %item.strip(),'a', encoding='utf8') as flei:
for it in a:
flei.write(str(it))
flei.write("\n")
if len(a) > 20 and len(a) <=30:
with open('path/realTweet_IDs_having_retweets_counts_21-30.txt','a', encoding='utf8') as fli:
fli.write(item)
fli.write("\n")
with open('path/realRetweeters of tweet %s.txt' %item.strip(),'a', encoding='utf8') as flei:
for it in a:
flei.write(str(it))
flei.write("\n")
if len(a) > 30 and len(a) <=40:
with open('path/realTweet_IDs_having_retweets_counts_31-40.txt','a', encoding='utf8') as fli:
fli.write(item)
fli.write("\n")
with open('path/realRetweeters of tweet %s.txt' %item.strip(),'a', encoding='utf8') as flei:
for it in a:
flei.write(str(it))
flei.write("\n")
if len(a) > 40:
with open('path/realTweet_IDs_having_retweets_counts_41_Onwards.txt','a', encoding='utf8') as flie:
flie.write(item)
flie.write("\n")
with open('path/realRetweeters of tweet %s.txt' %item.strip(),'a', encoding='utf8') as flei:
for it in a:
flei.write(str(it))
flei.write("\n")
a=[]