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") }
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 }
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) }
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) }