forked from smythp/twitter-workshop
-
Notifications
You must be signed in to change notification settings - Fork 8
/
api.py
46 lines (31 loc) · 1.1 KB
/
api.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
# -*- coding: utf-8 -*-
# tested with Python 3.4
import tweepy
import my_keys
# Set keys to variables. Note that they are imported from the my_keys.py file in the same folder
CONSUMER_KEY = my_keys.CONSUMER_KEY
CONSUMER_SECRET = my_keys.CONSUMER_SECRET
ACCESS_KEY = my_keys.ACCESS_KEY
ACCESS_SECRET = my_keys.ACCESS_SECRET
# Connect to API with the keys set above using the Tweepy library
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
###############
# Some things to try. Try uncommenting the lines with three hashes (###)
###############
# Print my account name
me = api.me().name
print(me)
# Update my status
### api.update_status(status="Look at me! I'm tweeting this using APIs. #DHRI @psmyth01 @SteveZweibel")
# Perform a search
### results = api.search(q="#NYCDHWeek")
### for result in results:
### print('\n')
### print(result.text)
# Write your search to a file (make sure the section above is uncommented)
### f = open('search.txt','w')
### for result in results:
### f.write(result.text)
### f.close()