File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -5,3 +5,7 @@ YELP_CONSUMER_KEY=
5
5
YELP_CONSUMER_SECRET=
6
6
YELP_TOKEN=
7
7
YELP_TOKEN_SECRET=
8
+ TWITTER_CONSUMER_KEY=
9
+ TWITTER_CONSUMER_SECRET=
10
+ TWITTER_TOKEN=
11
+ TWITTER_TOKEN_SECRET=
Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments