Skip to content

Commit 2b17fae

Browse files
Twitter API done
1 parent 08c998c commit 2b17fae

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

.env_sample

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ YELP_CONSUMER_KEY=
55
YELP_CONSUMER_SECRET=
66
YELP_TOKEN=
77
YELP_TOKEN_SECRET=
8+
TWITTER_CONSUMER_KEY=
9+
TWITTER_CONSUMER_SECRET=
10+
TWITTER_TOKEN=
11+
TWITTER_TOKEN_SECRET=

api_twitter.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import os
2+
3+
import twitter
4+
5+
consumer_key = os.getenv('TWITTER_CONSUMER_KEY')
6+
consumer_secret = os.getenv('TWITTER_CONSUMER_SECRET')
7+
access_token_key = os.getenv('TWITTER_TOKEN')
8+
access_token_secret = os.getenv('TWITTER_TOKEN_SECRET')
9+
10+
def obtain(search_term, category):
11+
12+
api = twitter.Api(
13+
consumer_key=consumer_key,
14+
consumer_secret=consumer_secret,
15+
access_token_key=access_token_key,
16+
access_token_secret=access_token_secret
17+
)
18+
19+
try:
20+
tweets = api.GetSearch(
21+
term="%s" % search_term
22+
)
23+
except BaseException:
24+
return None
25+
26+
print tweets[0].user
27+
28+
return {
29+
"metadata": {
30+
"type": "twitter-tweet",
31+
"term": search_term,
32+
"category": "category"
33+
},
34+
"data": {
35+
"author": tweets[0].user.name,
36+
"authorImage": tweets[0].user.profile_image_url,
37+
"tweet": tweets[0].text
38+
}
39+
}
40+
41+

0 commit comments

Comments
 (0)