Can now accept location
This commit is contained in:
@@ -32,7 +32,6 @@ func readRouteStopsData(busStops *map[string]*BusStop, buff *bytes.Buffer) (*[]*
|
||||
if busStop == nil {
|
||||
busStop = &BusStop{
|
||||
BusStopId: entry.StationId,
|
||||
Name_en: "???", Name_tc: "???", Name_sc: "???",
|
||||
}
|
||||
busStop.Reload()
|
||||
|
||||
@@ -76,37 +75,15 @@ func readRouteStopsData(busStops *map[string]*BusStop, buff *bytes.Buffer) (*[]*
|
||||
return &allRouteStops, nil
|
||||
}
|
||||
|
||||
func readBusStopsData(buff *bytes.Buffer) (*map[string]*BusStop, error) {
|
||||
busStopsData := BusStops{}
|
||||
err := json.Unmarshal(buff.Bytes(), &busStopsData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
busStopMap := map[string]*BusStop{}
|
||||
for _, entry := range busStopsData.BusStops {
|
||||
|
||||
entry.Reload()
|
||||
|
||||
if _, ok := busStopMap[entry.BusStopId]; ok {
|
||||
return nil, fmt.Errorf("Duplicated BusStop: %s", entry.BusStopId)
|
||||
}
|
||||
|
||||
busStopMap[entry.BusStopId] = entry
|
||||
}
|
||||
return &busStopMap, nil
|
||||
}
|
||||
|
||||
func getRouteStops() (*[]query.ISearchable, error) {
|
||||
var busStopMap *map[string]*BusStop
|
||||
func readBusStopsData() (*map[string]*BusStop, error) {
|
||||
busStopsData := BusStopsJson{}
|
||||
|
||||
QUERY_FUNC := func() (io.ReadCloser, error) {
|
||||
return utils.HttpGet("https://data.etabus.gov.hk/v1/transport/kmb/stop")
|
||||
}
|
||||
|
||||
PARSE_FUNC := func(buff *bytes.Buffer) error {
|
||||
var err error
|
||||
busStopMap, err = readBusStopsData(buff)
|
||||
err := json.Unmarshal(buff.Bytes(), &busStopsData)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -120,18 +97,49 @@ func getRouteStops() (*[]query.ISearchable, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
busStopMap := map[string]*BusStop{}
|
||||
for _, entry := range busStopsData.BusStops {
|
||||
|
||||
b := BusStop{
|
||||
BusStopId: entry.BusStopId,
|
||||
}
|
||||
|
||||
b.Latitude = entry.Latitude
|
||||
b.Longitude = entry.Longitude
|
||||
|
||||
n := map[string]string{
|
||||
"en": entry.Name_en,
|
||||
"zh-Hant": entry.Name_tc,
|
||||
"zh-Hans": entry.Name_sc,
|
||||
}
|
||||
|
||||
b.Name = &n
|
||||
|
||||
b.Reload()
|
||||
|
||||
if _, ok := busStopMap[b.BusStopId]; ok {
|
||||
return nil, fmt.Errorf("Duplicated BusStop: %s", b.BusStopId)
|
||||
}
|
||||
|
||||
busStopMap[b.BusStopId] = &b
|
||||
}
|
||||
return &busStopMap, nil
|
||||
}
|
||||
|
||||
func getRouteStops(busStopMap *map[string]*BusStop) (*[]query.ISearchable, error) {
|
||||
var routeStops *[]*RouteStop
|
||||
QUERY_FUNC = func() (io.ReadCloser, error) {
|
||||
|
||||
QUERY_FUNC := func() (io.ReadCloser, error) {
|
||||
return utils.HttpGet("https://data.etabus.gov.hk/v1/transport/kmb/route-stop")
|
||||
}
|
||||
|
||||
PARSE_FUNC = func(buff *bytes.Buffer) error {
|
||||
PARSE_FUNC := func(buff *bytes.Buffer) error {
|
||||
var err error
|
||||
routeStops, err = readRouteStopsData(busStopMap, buff)
|
||||
return err
|
||||
}
|
||||
|
||||
cs, err = utils.CacheStreamEx(JSON_ROUTESTOPS, QUERY_FUNC)
|
||||
cs, err := utils.CacheStreamEx(JSON_ROUTESTOPS, QUERY_FUNC)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user