-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitter.py
32 lines (28 loc) · 826 Bytes
/
twitter.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
import tweepy
import datetime
import re
def txtProc(txt):
hasil = ' '.join(re.sub("(@[A-Za-z0-9]+)|([^0-9A-Za-z \t])|(\w+:\/\/\S+)", " ", txt).split()).lower()
return hasil
def getTweet(n=3):
key = ""
secretKey = ""
token = ""
tokenSecret = ""
auth = tweepy.OAuthHandler(key,secretKey)
auth.set_access_token(token,tokenSecret)
api = tweepy.API(auth)
tday=tday=datetime.date.today() - datetime.timedelta(days=5)
search_words = "vaksin covid"
date_since = str(tday)
new_search = search_words + " -filter:retweets"
tweets = tweepy.Cursor(api.search, q=new_search, lang="id", since=date_since).items(n)
items = []
for tweet in tweets:
item = []
item.append(tweet.id)
item.append(tweet.user.screen_name)
item.append(txtProc(tweet.text))
item.append(tweet.created_at)
items.append(item)
return items