-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
89 lines (76 loc) · 3.11 KB
/
main.go
File metadata and controls
89 lines (76 loc) · 3.11 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"encoding/json"
"fmt"
"log"
"math/rand"
"net/http"
"net/url"
"time"
"github.com/ChimeraCoder/anaconda"
"github.com/rk/go-cron"
)
type returnObject struct {
Path string `json:"path"`
Secret string `json:"secret"`
}
func (r *returnObject) JSON() []byte {
v, _ := json.Marshal(r)
return v
}
func init() {
cron.NewDailyJob(11, 0, 0, func(time.Time) {
if !state {
PostTweet()
}
state = false
})
}
func main() {
http.HandleFunc(stateObject.Path, handler)
http.ListenAndServe(":9580", nil)
}
func handler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
if r.FormValue(secret) == stateObject.Secret && r.URL.Path == stateObject.Path {
fmt.Println("State is now set")
state = true
stateObject.Path, stateObject.Secret = "/"+generateName(), generateName()
w.Write(stateObject.JSON())
http.HandleFunc(stateObject.Path, handler)
} else {
w.Write(errorObject.JSON())
}
}
func generateName() string {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
return fmt.Sprintf("%s-%s-%d", adjs[r.Intn(len(adjs))], nouns[r.Intn(len(nouns))], r.Intn(9999-1000)+1000)
}
func PostTweet() {
fmt.Println("Now posting tweet")
var err error
anaconda.SetConsumerKey(consumerKey)
anaconda.SetConsumerSecret(consumerSecret)
api := anaconda.NewTwitterApi(accessToken, accessSecret)
v := url.Values{}
Tweet, err = api.PostTweet("Testing...", v)
if err != nil {
log.Println("We have an error now ", err)
}
}
var (
adjs = []string{"autumn", "hidden", "bitter", "misty", "silent", "empty", "dry", "dark", "summer", "icy", "delicate", "quiet", "white", "cool", "spring", "winter", "patient", "twilight", "dawn", "crimson", "wispy", "weathered", "blue", "billowing", "broken", "cold", "damp", "falling", "frosty", "green", "long", "late", "lingering", "bold", "little", "morning", "muddy", "old", "red", "rough", "still", "small", "sparkling", "throbbing", "shy", "wandering", "withered", "wild", "black", "young", "holy", "solitary", "fragrant", "aged", "snowy", "proud", "floral", "restless", "divine", "polished", "ancient", "purple", "lively", "nameless"}
nouns = []string{"waterfall", "river", "breeze", "moon", "rain", "wind", "sea", "morning", "snow", "lake", "sunset", "pine", "shadow", "leaf", "dawn", "glitter", "forest", "hill", "cloud", "meadow", "sun", "glade", "bird", "brook", "butterfly", "bush", "dew", "dust", "field", "fire", "flower", "firefly", "feather", "grass", "haze", "mountain", "night", "pond", "darkness", "snowflake", "silence", "sound", "sky", "shape", "surf", "thunder", "violet", "water", "wildflower", "wave", "water", "resonance", "sun", "wood", "dream", "cherry", "tree", "fog", "frost", "voice", "paper", "frog", "smoke", "star"}
Tweet anaconda.Tweet
secret = "secret"
state = false
stateObject = returnObject{Path: "/start", Secret: "startSecret"}
errorObject = returnObject{Path: "error", Secret: "Secret not matched"}
)
const (
consumerKey = "<from twitter>"
consumerSecret = "<from twitter>"
accessToken = "<from twitter>"
accessSecret = "<from twitter>"
macAddress = "<from twitter>"
)