-
Notifications
You must be signed in to change notification settings - Fork 0
/
dirty.go
56 lines (43 loc) · 1.11 KB
/
dirty.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
package main
import (
"fmt"
"github.com/dghubble/go-twitter/twitter"
"github.com/dghubble/oauth1"
"math/rand"
"os"
"os/exec"
"time"
)
func snore(min int, max int) {
rand.Seed(time.Now().UnixNano())
seconds := rand.Intn(max-min) + min
msgBuf := fmt.Sprintf("Sleeping for %d seconds...", seconds)
logOut(msgBuf)
time.Sleep(time.Duration(seconds) * time.Second)
}
func logOut(msg string) {
fmt.Printf("[%v] - %v\n", time.Now().Format(time.RFC850), msg)
}
func initTwitter() *twitter.Client {
configAuth := oauth1.NewConfig(config.ConsumerKey, config.ConsumerSecret)
token := oauth1.NewToken(config.AccessToken, config.AccessSecret)
httpClient := configAuth.Client(oauth1.NoContext, token)
return twitter.NewClient(httpClient)
}
func tweetSomething(client *twitter.Client) {
for {
out, err := exec.Command(config.FortunePath, "-o").Output()
if err != nil {
logOut("Error running fortune from the system...")
os.Exit(1)
}
if len(string(out)) < 140 {
logOut(string(out))
_, _, err := client.Statuses.Update(string(out), nil)
if err != nil {
logOut(err.Error())
}
return
}
}
}