-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwitter_api.py
More file actions
39 lines (23 loc) · 777 Bytes
/
twitter_api.py
File metadata and controls
39 lines (23 loc) · 777 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
34
import pandas
import tweepy
import configparser
# read configs
config = configparser.ConfigParser()
config.read('config.ini')
api_key = config['twitter']['api_key']
api_key_secret = config['twitter']['api_key_secret']
access_token = config['twitter']['access_token']
access_token_secret = config['twitter']['access_token_secret']
# authentication
auth = tweepy.OAuthHandler(api_key, api_key_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
public_tweets = api.home_timeline()
columns = ['Time', 'User', 'Tweet']
data = []
for tweet in public_tweets:
data.append([tweet.created_at,tweet.user.screen_name, tweet.text])
df = pandas.DataFrame(data, columns=columns)
print(df)
#to save data to csv
df.to_csv('tweets.csv')