From f375f4f97ef0626947153a8cf28328b76dc75a31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AB=8F=E8=A8=AA=E5=AD=90?= Date: Fri, 16 Feb 2024 16:29:35 +0900 Subject: [PATCH] =?UTF-8?q?2.=20=E8=A1=8C=E5=88=97=E3=81=AE=E9=95=B7?= =?UTF-8?q?=E3=81=95=E3=81=AF88=E6=96=87=E5=AD=97=EF=BC=88=E7=A9=BA?= =?UTF-8?q?=E7=99=BD=E5=90=AB=E3=82=80=EF=BC=89=E3=81=BE=E3=81=A7=20&=20?= =?UTF-8?q?=E3=83=8D=E3=82=B9=E3=83=88=E3=81=AF3=E5=9B=9E=E3=81=BE?= =?UTF-8?q?=E3=81=A7=20(geturl=20+=20render)=20#3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/geturl.go | 22 +++++++++++++- src/render.go | 79 +++++++++++++++++++++++++++++++-------------------- 2 files changed, 69 insertions(+), 32 deletions(-) diff --git a/src/geturl.go b/src/geturl.go index d0b814b..c4cdf0b 100644 --- a/src/geturl.go +++ b/src/geturl.go @@ -20,7 +20,27 @@ func GetUrl (f Opts) (string, error) { m1 := string(minute[0]) m2 := string(minute[1]) - curl, _ := url.Parse("https://transit.yahoo.co.jp/search/result?from=" + url.QueryEscape(f.From) + "&to=" + url.QueryEscape(f.To) + "&y=" + year + "&m=" + month + "&d=" + day + "&hh=" + hour + "&m1=" + m1 + "&m2=" + m2 + "&type=" + f.Mode + "&ticket=ic&expkind=1&userpass=1&ws=" + f.Route + "&al=" + b2s(f.NoAirplane) + "&shin=" + b2s(f.NoShinkansen) + "&ex=" + b2s(f.NoExpress) + "&hb=" + b2s(f.NoExpressBus) + "&lb=" + b2s(f.NoBus) + "&sr=" + b2s(f.NoFairy)) + curl, err := url.Parse( + "https://transit.yahoo.co.jp/search/result" + + "?from=" + url.QueryEscape(f.From) + + "&to=" + url.QueryEscape(f.To) + + "&y=" + year + + "&m=" + month + + "&d=" + day + + "&hh=" + hour + + "&m1=" + m1 + + "&m2=" + m2 + + "&type=" + f.Mode + + "&ticket=ic&expkind=1&userpass=1&ws=" + f.Route + + "&al=" + b2s(f.NoAirplane) + + "&shin=" + b2s(f.NoShinkansen) + + "&ex=" + b2s(f.NoExpress) + + "&hb=" + b2s(f.NoExpressBus) + + "&lb=" + b2s(f.NoBus) + + "&sr=" + b2s(f.NoFairy)) + if err != nil { + return "", nil + } return curl.String(), nil } diff --git a/src/render.go b/src/render.go index 8246126..7a0e495 100644 --- a/src/render.go +++ b/src/render.go @@ -6,46 +6,63 @@ import ( "github.com/gookit/color" ) -func Render (route []Route) { - var r, g, b uint8 - col := "fcfcfc" - fmt.Sscanf("ff7e56", "%2x%2x%2x", &r, &g, &b) - b1 := color.RGB(uint8(r), uint8(g), uint8(b)).Sprint("早") - fmt.Sscanf("60bddb", "%2x%2x%2x", &r, &g, &b) - b2 := color.RGB(uint8(r), uint8(g), uint8(b)).Sprint("楽") - fmt.Sscanf("fab60a", "%2x%2x%2x", &r, &g, &b) - b3 := color.RGB(uint8(r), uint8(g), uint8(b)).Sprint("安") - fmt.Sscanf(col, "%2x%2x%2x", &r, &g, &b) +var r, g, b uint8 +var col string + +func getFares(v Station, k int) { c := color.RGB(uint8(r), uint8(g), uint8(b)).Sprint("") + for i, fare := range v.Fares { + if k != i { continue } + + col = fare.Color + fmt.Sscanf(col, "%2x%2x%2x", &r, &g, &b) + text := fare.Train + + if fare.Platform != "" { text += "\n" + fare.Platform } + c = color.RGB(uint8(r), uint8(g), uint8(b)).Sprint(text) + fmt.Println(c) + } +} + +func Render (route []Route) { + col = "fcfcfc" + + fmt.Sscanf("ff7e56", "%2x%2x%2x", &r, &g, &b) + b1 := color.RGB(uint8(r), uint8(g), uint8(b)).Sprint("早") + + fmt.Sscanf("60bddb", "%2x%2x%2x", &r, &g, &b) + b2 := color.RGB(uint8(r), uint8(g), uint8(b)).Sprint("楽") + + fmt.Sscanf("fab60a", "%2x%2x%2x", &r, &g, &b) + b3 := color.RGB(uint8(r), uint8(g), uint8(b)).Sprint("安") + + fmt.Sscanf(col, "%2x%2x%2x", &r, &g, &b) + for key, value := range route { - color.Style{color.FgBlack, color.BgMagenta, color.OpBold}.Println("# ルート" + fmt.Sprintf("%d", key+1)) + color.Style{ + color.FgBlack, + color.BgMagenta, + color.OpBold, + }.Println("# ルート" + fmt.Sprintf("%d", key+1)) + badges := "" for _, badge := range value.Badges { - if badge == 1 { - badges += "〈" + b1 + "〉" - } - if badge == 2 { - badges += "〈" + b2 + "〉" - } - if badge == 3 { - badges += "〈" + b3 + "〉" - } + if badge == 1 { badges += "〈" + b1 + "〉" } + if badge == 2 { badges += "〈" + b2 + "〉" } + if badge == 3 { badges += "〈" + b3 + "〉" } } - fmt.Println(value.Time + " (" + value.Duration + "), " + value.Fare + ", 乗換数:" + value.TransitCunt + " " + badges) + + fmt.Println( + value.Time + " (" + value.Duration + "), " + + value.Fare + ", 乗換数:" + value.TransitCunt + " " + badges, + ) + for k, v := range value.Stations { fmt.Println(v.Time + " " + v.Name) - for i, fare := range v.Fares { - if k == i { - col = fare.Color - fmt.Sscanf(col, "%2x%2x%2x", &r, &g, &b) - text := fare.Train - if fare.Platform != "" { text += "\n" + fare.Platform } - c = color.RGB(uint8(r), uint8(g), uint8(b)).Sprint(text) - fmt.Println(c) - } - } + getFares(v, k) } + fmt.Println("") } }