Skip to content

Commit

Permalink
feat: rewrite usnws to use json
Browse files Browse the repository at this point in the history
  • Loading branch information
doomsower committed Oct 1, 2023
1 parent c549969 commit 799a804
Show file tree
Hide file tree
Showing 11 changed files with 670 additions and 222 deletions.
48 changes: 48 additions & 0 deletions core/coord_to_tz.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,54 @@ func CoordinateToTimezone(lat float64, lon float64) (string, error) {
return name, nil
}

// only those state that have strictly one timezone
var stateTimeZones = map[string]string{
"AL": "America/Chicago",
"AZ": "America/Phoenix",
"AR": "America/Chicago",
"CA": "America/Los_Angeles",
"CO": "America/Denver",
"CT": "America/New_York",
"DE": "America/New_York",
"DC": "America/New_York",
"GA": "America/New_York",
"HI": "Pacific/Honolulu",
"IL": "America/Chicago",
"IA": "America/Chicago",
"ME": "America/New_York",
"MD": "America/New_York",
"MA": "America/New_York",
"MN": "America/Chicago",
"MS": "America/Chicago",
"MO": "America/Chicago",
"MT": "America/Denver",
"NV": "America/Los_Angeles",
"NH": "America/New_York",
"NJ": "America/New_York",
"NM": "America/Denver",
"NY": "America/New_York",
"NC": "America/New_York",
"OH": "America/New_York",
"OK": "America/Chicago",
"PA": "America/New_York",
"RI": "America/New_York",
"SC": "America/New_York",
"UT": "America/Denver",
"VT": "America/New_York",
"VA": "America/New_York",
"WA": "America/Los_Angeles",
"WV": "America/New_York",
"WI": "America/Chicago",
"WY": "America/Denver",
}

func USCoordinateToTimezone(state string, lat float64, lon float64) (string, error) {
if name, ok := stateTimeZones[state]; ok {
return name, nil
}
return CoordinateToTimezone(lat, lon)
}

func CloseTimezoneDb() {
if tz != nil {
(*tz).Close()
Expand Down
17 changes: 15 additions & 2 deletions scripts/usnws/descriptor.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package usnws

import (
"fmt"

"github.com/whitewater-guide/gorge/core"
)

Expand All @@ -9,9 +11,20 @@ var Descriptor = &core.ScriptDescriptor{
Description: "U.S. National Oceanic and Atmospheric Administration's National Weather Service",
Mode: core.AllAtOnce,
DefaultOptions: func() interface{} {
return &optionsUsnws{}
return &optionsUsnws{
pageSize: 1000, // defaults to 5000 if not mentioned at all, total around 10500
numWorkers: 5,
}
},
Factory: func(name string, options interface{}) (core.Script, error) {
return &scriptUsnws{name: name, kmzUrl: "https://water.weather.gov/ahps/download.php?data=kmz_obs"}, nil
if opts, ok := options.(*optionsUsnws); ok {
return &scriptUsnws{
name: name,
url: "https://mapservices.weather.noaa.gov/eventdriven/rest/services/water/ahps_riv_gauges/MapServer/0/query",
pageSize: opts.pageSize,
numWorkers: opts.numWorkers,
}, nil
}
return nil, fmt.Errorf("failed to cast %T", optionsUsnws{})
},
}
190 changes: 0 additions & 190 deletions scripts/usnws/kmz_reader.go

This file was deleted.

Loading

0 comments on commit 799a804

Please sign in to comment.