-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcorona_tweets.py
139 lines (103 loc) · 4.27 KB
/
corona_tweets.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<<<<<<< HEAD
import tweepy
import datetime
import xlsxwriter
import sys
#My Twitter Account Information
#the real values are hidden
consumer_key = ""
consumer_secret = ""
access_token = "1"
access_token_secret = ""
#Collect all the tweets in a list
tweets = []
#windows
#dsdsdsa
#date filter
start="2020-04-01"
end= "2020-04-02"
#startDate = datetime.datetime(2020, 4, 1, 0, 0, 0)
#endDate = datetime.datetime(2020, 4, 15, 0, 0, 0)
# Replace the API_KEY and API_SECRET with your application's key and secret.
auth = tweepy.AppAuthHandler(consumer_key, consumer_secret)
api = tweepy.API(auth, wait_on_rate_limit=True,wait_on_rate_limit_notify=True)
if (not api):
print ("Can't Authenticate")
sys.exit(-1)
# Continue with rest of code
#Another alternative to tweepy, tweepy could give more results and more feautare but we can
#only use it for the last week tweets.
#Informarion for Old Tweets https://pypi.org/project/GetOldTweets3/
#https://github.com/Jefferson-Henrique/GetOldTweets-python
#Information for tweepy
#https://bhaskarvk.github.io/2015/01/how-to-use-twitters-search-rest-api-most-effectively./
#https://gist.github.com/alexdeloy/fdb36ad251f70855d5d6
# https://readthedocs.org/projects/tweepy/downloads/pdf/latest/
import GetOldTweets3 as got
queries = ['corona vefat', 'corona öldü' , 'coronadan vefat' , 'coronadan öldü', 'coronavirus vefat','coronavirus öldü']
workbook = xlsxwriter.Workbook('tweetsaboutdeaths' + ".xlsx")
worksheet = workbook.add_worksheet('ff')
row = 0
for query in queries:
tweetCriteria = got.manager.TweetCriteria().setQuerySearch(query)\
.setSince(start)\
.setUntil(end)\
.setMaxTweets(100000)
for tweet in got.manager.TweetManager.getTweets(tweetCriteria):
worksheet.write_string(row, 0, str(tweet.id))
worksheet.write_string(row, 1, str(tweet.date))
worksheet.write(row, 2, tweet.text)
worksheet.write(row, 3,query)
# worksheet.write_string(row, 3, str(tweet.geo ))
row += 1
=======
import tweepy
import datetime
import xlsxwriter
import sys
#My Twitter Account Information
#the real values are hidden
consumer_key = ""
consumer_secret = ""
access_token = "1"
access_token_secret = ""
#Collect all the tweets in a list
tweets = []
start="2020-04-01"
end= "2020-04-02"
#startDate = datetime.datetime(2020, 4, 1, 0, 0, 0)
#endDate = datetime.datetime(2020, 4, 15, 0, 0, 0)
# Replace the API_KEY and API_SECRET with your application's key and secret.
auth = tweepy.AppAuthHandler(consumer_key, consumer_secret)
api = tweepy.API(auth, wait_on_rate_limit=True,wait_on_rate_limit_notify=True)
if (not api):
print ("Can't Authenticate")
sys.exit(-1)
# Continue with rest of code
#Another alternative to tweepy, tweepy could give more results and more feautare but we can
#only use it for the last week tweets.
#Informarion for Old Tweets https://pypi.org/project/GetOldTweets3/
#https://github.com/Jefferson-Henrique/GetOldTweets-python
#Information for tweepy
#https://bhaskarvk.github.io/2015/01/how-to-use-twitters-search-rest-api-most-effectively./
#https://gist.github.com/alexdeloy/fdb36ad251f70855d5d6
# https://readthedocs.org/projects/tweepy/downloads/pdf/latest/
import GetOldTweets3 as got
queries = ['corona vefat', 'corona öldü' , 'coronadan vefat' , 'coronadan öldü', 'coronavirus vefat','coronavirus öldü']
workbook = xlsxwriter.Workbook('tweetsaboutdeaths' + ".xlsx")
worksheet = workbook.add_worksheet('ff')
row = 0
for query in queries:
tweetCriteria = got.manager.TweetCriteria().setQuerySearch(query)\
.setSince(start)\
.setUntil(end)\
.setMaxTweets(100000)
for tweet in got.manager.TweetManager.getTweets(tweetCriteria):
worksheet.write_string(row, 0, str(tweet.id))
worksheet.write_string(row, 1, str(tweet.date))
worksheet.write(row, 2, tweet.text)
worksheet.write(row, 3,query)
# worksheet.write_string(row, 3, str(tweet.geo ))
row += 1
>>>>>>> 98f844f62c08086864c53e82f7ca8ae95d16e3fa
workbook.close()