/
controller.go
74 lines (68 loc) · 1.65 KB
/
controller.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"github.com/mattn/go-gtk/gdkpixbuf"
"http"
"json"
"io"
"io/ioutil"
"strings"
"gotter"
"github.com/garyburd/twister/oauth"
"log"
)
type Accounts struct {
Name string
Credentials *oauth.Credentials
Maxreadid int64
}
func Connect() Accounts{
var account Accounts
file, config := gotter.GetConfig("zwitscher")
config["ClientToken"] = "lhCgJRAE1ECQzwVXfs5NQ"
config["ClientSecret"] = "qk9i30vuzWHspsRttKsYrnoKSw9XBmWHdsis76z4"
token, authorized, err := gotter.GetAccessToken(config)
if err != nil {
log.Fatal("faild to get access token:", err)
}
if authorized {
b, err := json.MarshalIndent(config, "", " ")
if err != nil {
log.Fatal("failed to store file:", err)
}
err = ioutil.WriteFile(file, b, 0700)
if err != nil {
log.Fatal("failed to store file:", err)
}
}
account.Credentials = token
return account
}
func url2pixbuf(url string) *gdkpixbuf.GdkPixbuf {
r, err := http.Get(url)
if err != nil {
return nil
}
t := r.Header.Get("Content-Type")
b := make([]byte, r.ContentLength)
if _, err = io.ReadFull(r.Body, b); err != nil {
return nil
}
var loader *gdkpixbuf.GdkPixbufLoader
if strings.Index(t, "jpeg") >= 0 {
loader, _ = gdkpixbuf.PixbufLoaderWithMimeType("image/jpeg")
} else {
loader, _ = gdkpixbuf.PixbufLoaderWithMimeType("image/png")
}
loader.SetSize(24, 24)
loader.Write(b)
loader.Close()
return loader.GetPixbuf()
}
func SendTweet(text string) {
gotter.PostTweet(accounts.Credentials, "https://api.twitter.com/1/statuses/update.json", map[string]string{"status": text})
}
func addReply(id string,name string){
println(name)
println(id)
//newTweetTextField.SetText("")
}