Beispiel #1
0
func CreateConfigureFile(accessToken string, accessTokenSelect string, consumerKey string, consumerSelect string, fileName string) {
	if fileName == "" {
		fileName = "../conf/configure.json"
	}
	c := Conf{accessToken, accessTokenSelect, consumerKey, consumerSelect}
	js, err := json.Marshal(c)
	log.Terminate(err, "../log/error.json")
	err = ioutil.WriteFile(fileName, js, 0644)
	log.Terminate(err, "../log/error.json")
}
Beispiel #2
0
func LoadConfigure(fileName string) *Conf {
	if fileName == "" {
		fileName = "../conf/configure.json"
	}
	js, err := ioutil.ReadFile(fileName)
	log.Terminate(err, "../log/error.json")
	c := Conf{}
	err = json.Unmarshal(js, &c)
	log.Terminate(err, "../log/error.json")
	return &c
}
Beispiel #3
0
func RandomPost() {
	rand.Seed(time.Now().UnixNano())
	c := LoadConfigure("")
	rp := Random{}
	rjs, err := ioutil.ReadFile("../data/random.json")
	log.Terminate(err, "../log/posterr.json")
	err = json.Unmarshal(rjs, &rp)
	log.Terminate(err, "../log/posterr.json")
	p := rand.Intn(len(rp.PostData))

	anaconda.SetConsumerKey(c.ConsumerKey)
	anaconda.SetConsumerSecret(c.ConsumerSelect)
	api := anaconda.NewTwitterApi(c.AccessToken, c.AccessTokenSelect)
	api.PostTweet(rp.PostData[p].Post, nil)

}
Beispiel #4
0
func RegistRandomPost(post string) {
	rp := Random{}
	rjs, err := ioutil.ReadFile("../data/random.json")

	if err == nil {
		err = json.Unmarshal(rjs, &rp)
		log.Terminate(err, "../log/error.json")
	}
	d := Data{Post: post}
	datas := rp.PostData
	datas = append(datas, d)
	rp.PostData = datas
	bin, _ := json.Marshal(rp)
	ioutil.WriteFile("../data/random.json", bin, 0644)
}