-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitter.go
57 lines (48 loc) · 1.33 KB
/
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
50
51
52
53
54
55
56
57
package main
import (
"encoding/base64"
"fmt"
"io/ioutil"
"net/url"
"strconv"
"github.com/ChimeraCoder/anaconda"
_ "github.com/davecgh/go-spew/spew"
"github.com/kaosfere/aptdata"
"github.com/spf13/viper"
)
type credentials struct {
consumerKey string
consumerSecret string
accessToken string
accessTokenSecret string
}
func post(c credentials, apt *aptdata.Airport) error {
anaconda.SetConsumerKey(c.consumerKey)
anaconda.SetConsumerSecret(c.consumerSecret)
api := anaconda.NewTwitterApi(c.accessToken, c.accessTokenSecret)
data, err := ioutil.ReadFile(fmt.Sprintf("%s/%s", viper.GetString("outdir"), "out.png"))
if err != nil {
return err
}
mediaString := base64.StdEncoding.EncodeToString(data)
media, err := api.UploadMedia(mediaString)
if err != nil {
return err
}
latitude := strconv.FormatFloat(apt.Latitude, 'f', -1, 64)
longitude := strconv.FormatFloat(apt.Longitude, 'f', -1, 64)
location := fmt.Sprintf("%s, %s", apt.Region, apt.Country)
if apt.City != "" {
location = fmt.Sprintf("%s, %s", apt.City, location)
}
v := url.Values{}
v.Set("media_ids", media.MediaIDString)
v.Set("lat", latitude)
v.Set("long", longitude)
v.Set("location", location)
v.Set("display_coordinates", "true")
// tweet, err := api.PostTweet("", v)
// spew.Dump(tweet)
_, err = api.PostTweet("", v)
return err
}