-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitter.go
49 lines (38 loc) · 993 Bytes
/
twitter.go
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
46
47
48
49
package main
import (
"net/url"
"os"
"github.com/ChimeraCoder/anaconda"
)
func connectWithApi() *anaconda.TwitterApi {
consumerKey := os.Getenv("CONSUMER_KEY")
consumerSecret := os.Getenv("CUSTOMER_SECRET")
accessToken := os.Getenv("ACCESS_TOKEN")
accessTokenSecret := os.Getenv("ACCESS_TOKEN_SECRET")
anaconda.SetConsumerKey(consumerKey)
anaconda.SetConsumerSecret(consumerSecret)
api := anaconda.NewTwitterApi(accessToken, accessTokenSecret)
return api
}
func GetTrends() []anaconda.Trend {
api := connectWithApi()
defer api.Close()
trendResponse, err := api.GetTrendsByPlace(23424977, nil)
if err != nil {
panic(err)
}
return trendResponse.Trends
}
func GetTweets(trend anaconda.Trend) []anaconda.Tweet {
api := connectWithApi()
defer api.Close()
v := url.Values{}
v.Set("result_type", "mixed")
v.Set("lang", "en")
v.Set("count", "100")
searchResult, err := api.GetSearch(trend.Query, v)
if err != nil {
panic(err)
}
return searchResult.Statuses
}