Added kmb schedules
This commit is contained in:
@@ -16,16 +16,18 @@ import (
|
||||
var JSON_ROUTESTOPS string = filepath.Join( utils.WORKDIR, "kmb-routestops.json" )
|
||||
var JSON_BUSSTOPS string = filepath.Join( utils.WORKDIR, "kmb-busstops.json" )
|
||||
|
||||
func readRouteStopsData( busStops *map[string] *BusStop, buff *bytes.Buffer ) error {
|
||||
func readRouteStopsData( busStops *map[string] *BusStop, buff *bytes.Buffer ) ( *[] *RouteStop, error ) {
|
||||
|
||||
routeStopsData := RouteStops{}
|
||||
err := json.Unmarshal( buff.Bytes(), &routeStopsData )
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// routeStops[ Route ][ ServiceType ][ Direction ][ Seq ] = RouteStop
|
||||
routeStops := map[string] *map[string] *map[ string ] *map[ int ] *RouteStop{}
|
||||
allRouteStops := [] *RouteStop{}
|
||||
|
||||
for _, entry := range routeStopsData.RouteStops {
|
||||
|
||||
busStop := (*busStops)[ entry.StationId ]
|
||||
@@ -63,16 +65,17 @@ func readRouteStopsData( busStops *map[string] *BusStop, buff *bytes.Buffer ) er
|
||||
if direction == nil {
|
||||
direction = &map[ int ] *RouteStop{}
|
||||
(*service)[ entry.Direction ] = direction
|
||||
entry.RouteStops = direction
|
||||
}
|
||||
entry.RouteStops = direction
|
||||
|
||||
seq := (*direction)[ entry.StationSeq ]
|
||||
if seq == nil {
|
||||
(*direction)[ entry.StationSeq ] = entry
|
||||
}
|
||||
allRouteStops = append( allRouteStops, entry )
|
||||
}
|
||||
|
||||
return nil
|
||||
return &allRouteStops, nil
|
||||
}
|
||||
|
||||
func readBusStopsData( buff *bytes.Buffer ) ( *map[string]*BusStop, error ) {
|
||||
@@ -96,7 +99,7 @@ func readBusStopsData( buff *bytes.Buffer ) ( *map[string]*BusStop, error ) {
|
||||
return &busStopMap, nil
|
||||
}
|
||||
|
||||
func getBusStops() (*[] query.ISearchable, error) {
|
||||
func getRouteStops() (*[] query.ISearchable, error) {
|
||||
|
||||
QUERY_FUNC := func() ( io.ReadCloser, error ) {
|
||||
resp, err := http.Get( "https://data.etabus.gov.hk/v1/transport/kmb/stop" )
|
||||
@@ -129,14 +132,15 @@ func getBusStops() (*[] query.ISearchable, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = readRouteStopsData( busStopMap, buff )
|
||||
routeStops, err := readRouteStopsData( busStopMap, buff )
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
searchables := [] query.ISearchable{}
|
||||
for _, busStop := range *busStopMap {
|
||||
searchables = append( searchables, busStop )
|
||||
for _, routeStop := range *routeStops {
|
||||
searchables = append( searchables, routeStop )
|
||||
routeStop.Reload()
|
||||
}
|
||||
|
||||
return &searchables, nil
|
||||
|
||||
Reference in New Issue
Block a user