-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtrial_append.py
More file actions
45 lines (33 loc) · 1.02 KB
/
trial_append.py
File metadata and controls
45 lines (33 loc) · 1.02 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
import tweepy as tw
import openpyxl as px
import schedule
import time
consumer_key = "[INSERT CONSUMER KEY]"
consumer_secret = "[INSERT CONSUMER SECRET]"
access_token = "[INSERT ACCESS TOKEN]"
access_token_secret = "[INSERT ACCESS TOKEN SECRET]"
auth = tw.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tw.API(auth)
def append():
tweets = tw.Cursor(api.search, q="#freespeech", lang="en", date="2021-7-5", tweet_mode="extended").items(5)
text = []
likes = []
time = []
for tweet in tweets:
text.append(tweet.full_text)
likes.append(tweet.favorite_count)
time.append(tweet.created_at)
wb = px.load_workbook("speech_test.xlsx")
ws = wb.active
rows = []
for i in range(5):
rows.append([" ", text[i], likes[i], time[i]])
for row in rows:
ws.append(row)
wb.save("speech_test.xlsx")
wb.close()
schedule.every(1).minutes.do(append)
while True:
schedule.run_pending()
time.sleep(1)