Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 11 additions & 79 deletions yukicoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,87 +6,19 @@ import (
"log"
"net/http"
"strconv"
"strings"
"time"
)

type Yukicoder struct {
Kind string `json:"kind"`
Etag string `json:"etag"`
Summary string `json:"summary"`
Description string `json:"description"`
Updated time.Time `json:"updated"`
TimeZone string `json:"timeZone"`
AccessRole string `json:"accessRole"`
DefaultReminders []interface{} `json:"defaultReminders"`
NextSyncToken string `json:"nextSyncToken"`
Items []struct {
Kind string `json:"kind"`
Etag string `json:"etag"`
ID string `json:"id"`
Status string `json:"status"`
HTMLLink string `json:"htmlLink"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
Summary string `json:"summary"`
Description string `json:"description"`
Location string `json:"location"`
Creator struct {
Email string `json:"email"`
DisplayName string `json:"displayName"`
Self bool `json:"self"`
} `json:"creator"`
Organizer struct {
Email string `json:"email"`
DisplayName string `json:"displayName"`
Self bool `json:"self"`
} `json:"organizer"`
Start struct {
DateTime time.Time `json:"dateTime"`
} `json:"start"`
End struct {
DateTime time.Time `json:"dateTime"`
} `json:"end"`
ICalUID string `json:"iCalUID"`
Sequence int `json:"sequence"`
} `json:"items"`
}

// yukicoderのJSONファイルのURLを返す
func GetYukicoderURL() string {
now := time.Now()
itoa := func(t int) string {
return strconv.Itoa(t)
}
year, month, day := now.Year(), itoa(int(now.Month())), itoa(now.Day())
// 1文字なら戦闘に0を付け加える
if len(month) == 1 {
month = "0" + month
}
if len(day) == 1 {
day = "0" + day
}

// テキストに書いてるURL情報を読み込む
urlByteArray, err := ioutil.ReadFile("yukicoder_url.txt")
if err != nil {
log.Printf("Faild to open yukicoder_url.txt: %v", err)
}
urlSlice := strings.Split(string(urlByteArray), ",")

// 今日からプラスマイナス1年分のデータを抜き出すURLを生成
url := urlSlice[0]
url += itoa(year-1) + "-" + month + "-" + day
url += urlSlice[1]
url += itoa(year+1) + "-" + month + "-" + day
url += urlSlice[2]

return url
Id int
Name string
Date time.Time
EndDate time.Time
}

func GetYukicoder() ([]RawContest, bool) {
// 外部からデータを取得
res, err := http.Get(GetYukicoderURL())
res, err := http.Get("https://yukicoder.me/api/v1/contest/future")
if err != nil {
log.Printf("Faild to GET reqest(yukicoder): %v", err)
return nil, false
Expand All @@ -101,18 +33,18 @@ func GetYukicoder() ([]RawContest, bool) {
}

// jsonを解析してCodeForcesの構造体にデータを入れる
var yukicoder Yukicoder
var yukicoder []Yukicoder
json.Unmarshal(body, &yukicoder)

var contests []RawContest
for _, result := range yukicoder.Items {
name := result.Summary
url := "https://yukicoder.me/contests/" + result.ICalUID
start := result.Start.DateTime.Unix()
for _, result := range yukicoder {
name := result.Name
url := "https://yukicoder.me/contests/" + strconv.Itoa(result.Id)
start := result.Date.Unix()
if now := time.Now().Unix(); now >= start {
continue
}
end := result.End.DateTime.Unix()
end := result.EndDate.Unix()
contest := RawContest{
Name: name,
URL: url,
Expand Down