File tree Expand file tree Collapse file tree 5 files changed +71
-12
lines changed
Expand file tree Collapse file tree 5 files changed +71
-12
lines changed Original file line number Diff line number Diff line change @@ -4,12 +4,12 @@ import (
44 "fmt"
55 "os"
66
7- "github.com/otiai10/amesh/lib/rainnow "
7+ "github.com/otiai10/amesh/lib/tenki "
88 "github.com/otiai10/gat/render"
99)
1010
11- // Rainnow ...
12- func Rainnow (r render.Renderer , location rainnow .Location ) error {
11+ // Tenki
12+ func Tenki (r render.Renderer , location tenki .Location ) error {
1313 entry := location .GetEntry ()
1414 img , err := entry .Image ()
1515 if err != nil {
Original file line number Diff line number Diff line change 1- package rainnow
1+ package tenki
22
33import (
44 "image"
@@ -8,10 +8,8 @@ import (
88)
99
1010const (
11- // TenkiStaticURL ...
12- TenkiStaticURL = "https://static.tenki.jp/static-images"
1311 // JapanEntryPath ...
14- JapanEntryPath = "/radar/2006/01/02/15/04/00/ japan-detail-large.jpg"
12+ JapanEntryPath = "/japan-detail-large.jpg"
1513)
1614
1715// Japan ...
@@ -31,7 +29,7 @@ func (japan Japan) GetEntry() Entry {
3129 }
3230 now := truncateTime (time .Now ().In (loc ), 5 * time .Minute )
3331 return JapanEntry {
34- URL : TenkiStaticURL + now .Format (JapanEntryPath ) ,
32+ URL : TenkiStaticURL + now .Format (TenkiDynamicTimestampPath ) + JapanEntryPath ,
3533 }
3634}
3735
Original file line number Diff line number Diff line change 1+ package tenki
2+
3+ import (
4+ "image"
5+ "log"
6+ "net/http"
7+ "time"
8+ )
9+
10+ const (
11+ // TenkiStaticURL ...
12+ OsakaEntryPath = "/pref-30-large.jpg"
13+ )
14+
15+ // Osaka ...
16+ type Osaka struct {}
17+
18+ // OsakaEntry ...
19+ type OsakaEntry struct {
20+ URL string
21+ }
22+
23+ // GetEntry ...
24+ func (osaka Osaka ) GetEntry () Entry {
25+ area := "Asia/Tokyo"
26+ loc , err := time .LoadLocation (area )
27+ if err != nil {
28+ log .Fatalf ("Failed to load location `%s`" , area )
29+ }
30+ now := truncateTime (time .Now ().In (loc ), 5 * time .Minute )
31+ return OsakaEntry {
32+ URL : TenkiStaticURL + now .Format (TenkiDynamicTimestampPath ) + OsakaEntryPath ,
33+ }
34+ }
35+
36+ // Image ...
37+ func (osaka OsakaEntry ) Image (client ... * http.Client ) (image.Image , error ) {
38+ if len (client ) == 0 {
39+ client = append (client , http .DefaultClient )
40+ }
41+ res , err := client [0 ].Get (osaka .URL )
42+ if err != nil {
43+ return nil , err
44+ }
45+ defer res .Body .Close ()
46+ img , _ , err := image .Decode (res .Body )
47+ return img , err
48+ }
49+
50+ // ReferenceURL ...
51+ func (osaka OsakaEntry ) ReferenceURL () string {
52+ return "https://tenki.jp/"
53+ }
Original file line number Diff line number Diff line change 1- package rainnow
1+ package tenki
22
33import (
44 "image"
55 "net/http"
66 "time"
77)
88
9+ const (
10+ // TenkiStaticURL ...
11+ TenkiStaticURL = "https://static.tenki.jp/static-images"
12+ // TenkiDynamicTimestampPath ...
13+ TenkiDynamicTimestampPath = "/radar/2006/01/02/15/04/00"
14+ )
15+
916// Location ...
1017type Location interface {
1118 GetEntry () Entry
@@ -19,6 +26,7 @@ type Entry interface {
1926
2027var supported = map [string ]Location {
2128 "japan" : Japan {},
29+ "osaka" : Osaka {},
2230}
2331
2432// GetLocation ...
Original file line number Diff line number Diff line change 99 "os"
1010
1111 "github.com/otiai10/amesh/cli"
12- "github.com/otiai10/amesh/lib/rainnow "
12+ "github.com/otiai10/amesh/lib/tenki "
1313 "github.com/otiai10/gat/render"
1414)
1515
@@ -53,9 +53,9 @@ func main() {
5353 }
5454 renderer .SetScale (scale )
5555 subcommand := flag .Arg (0 )
56- switch loc := rainnow .GetLocation (subcommand ); {
56+ switch loc := tenki .GetLocation (subcommand ); {
5757 case loc != nil :
58- onerror (cli .Rainnow (renderer , loc ))
58+ onerror (cli .Tenki (renderer , loc ))
5959 case subcommand == "typhoon" :
6060 onerror (cli .Typhoon (renderer ))
6161 case lapse :
You can’t perform that action at this time.
0 commit comments