This repository has been archived by the owner on Aug 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
78 lines (63 loc) · 2.01 KB
/
main.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
75
76
77
78
package main
import (
"os"
"fmt"
"time"
"regexp"
"strings"
"net/http"
"io/ioutil"
"github.com/ChimeraCoder/anaconda"
)
const (
url = "http://www.topre.co.jp/products/elec/keyboards/index.html"
)
func fetchTopre(url string) (string, error) {
res, err := http.Get(url)
if err != nil {
fmt.Println(err)
}
defer res.Body.Close()
fmt.Println("fetched", url)
byteArray, _ := ioutil.ReadAll(res.Body)
html_text := string(byteArray)
return html_text, err
}
func tweet(api *anaconda.TwitterApi, tweet_text string) anaconda.Tweet {
tweeted_text, err := api.PostTweet(tweet_text, nil)
if err != nil {
fmt.Println(err)
}
return tweeted_text
}
func main() {
search_words := []string{"スプリット", "左右", "セパレート", "分離"}
api_key := os.Getenv("TSB_API_KEY")
api_secret := os.Getenv("TSB_API_SECRET")
con_key := os.Getenv("TSB_CONSUMER_KEY")
con_secret := os.Getenv("TSB_CONSUMER_SECRET")
fmt.Println(os.Environ())
api := anaconda.NewTwitterApiWithCredentials(api_key, api_secret, con_key, con_secret)
html_text, _ := fetchTopre(url)
find_flag := false
var find_words []string
for _, word := range search_words {
r := regexp.MustCompile(word)
if r.MatchString(html_text) {
find_words = append(find_words, word)
find_flag = true
}
}
tweet_text := ""
if find_flag {
tweet_text = time.Now().Format("1月2日15時4分") + "現在、" + url + " に 「" + strings.Join(find_words, ",") + "」が見つかりました。スプリットキーボードが発売されるといいね✨"
} else if time.Now().Hour() == 23 - 9 {
tweet_text = time.Now().Format("1月2日") + "はスプリットキーボードが発表されなかったね…また明日に期待💁🏼♀️"
} else {
tweet_text = ""
}
if tweet_text != "" {
tweeted_text := tweet(api, tweet_text)
fmt.Print(tweeted_text)
}
}