-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwitterScraper.py
More file actions
33 lines (25 loc) · 982 Bytes
/
Copy pathtwitterScraper.py
File metadata and controls
33 lines (25 loc) · 982 Bytes
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
import codecs, json
import Tweepy
config = ConfigParser()
config.read('twitterauth.ini')
access_token = config.get('auth','ACCESS_TOKEN')
access_token_secret = config.get('auth', 'ACCESS_TOKEN_SECRET')
consumer_key = config.get('auth', 'CONSUMER_KEY')
consumer_secret = config.get('auth','CONSUMER_SECRET')
'''
print(access_token)
print(access_token_secret)
print(consumer_key)
print(consumer_secret)
'''
def twitter_init():
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
return api
# Create Scraper
extractor = twitter_init()
tweets = tweepy.Cursor(extractor.search, q="Border Wall -filter:retweets", geocode="33.422558,-112.118664,75km").items(2000)
data = pd.DataFrame(data=[tweet.text for tweet in tweets], columns=['Tweets'])
display(data.head(2000))
data.to_json(r'C:/Users/u180530/Desktop/FYP/Data/PHOBorderWall.json')