feat: include line id in LineInfo
This commit is contained in:
parent
acac91dbfa
commit
bcfeabc9c1
@ -3,49 +3,51 @@ package scraper
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"log"
|
||||
)
|
||||
|
||||
type Coords struct {
|
||||
Lat, Lon float64
|
||||
Lat float64 `json:"lat"`
|
||||
Lon float64 `json:"lon"`
|
||||
}
|
||||
|
||||
type Vehicle struct {
|
||||
GarageId string
|
||||
Coords Coords
|
||||
AtStationId int
|
||||
AtStationName string
|
||||
GarageId string `json:"garageId"`
|
||||
Coords Coords `json:"coords"`
|
||||
AtStationId int `json:"atStationId"`
|
||||
AtStationName string `json:"atStationName"`
|
||||
}
|
||||
|
||||
type StationInfo struct {
|
||||
Id int
|
||||
CityId int
|
||||
CityName string
|
||||
Name string
|
||||
Coords Coords
|
||||
Id int `json:"id"`
|
||||
CityId int `json:"cityId"`
|
||||
CityName string `json:"cityName"`
|
||||
Name string `json:"name"`
|
||||
Coords Coords `json:"coords"`
|
||||
}
|
||||
|
||||
type LineInfo struct {
|
||||
Name string
|
||||
Title string
|
||||
Stations []StationInfo
|
||||
Route []Coords
|
||||
Id int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Title string `json:"title"`
|
||||
Stations []StationInfo `json:"stations"`
|
||||
Route []Coords `json:"route"`
|
||||
}
|
||||
|
||||
type ScrapeResult struct {
|
||||
Id int
|
||||
Success bool
|
||||
SecondsLeft int
|
||||
LineInfo LineInfo
|
||||
Vehicles []Vehicle
|
||||
Id int `json:"id"`
|
||||
Success bool `json:"success"`
|
||||
SecondsLeft int `json:"secondsLeft"`
|
||||
LineInfo LineInfo `json:"lineInfo"`
|
||||
Vehicles []Vehicle `json:"vehicles"`
|
||||
}
|
||||
|
||||
type Station struct {
|
||||
Id int
|
||||
Id int `json:"id"`
|
||||
}
|
||||
|
||||
var Log = log.Default()
|
||||
@ -139,6 +141,13 @@ func Scrape(stations []Station, c ApiConfig) ([]ScrapeResult, error) {
|
||||
|
||||
var lineInfo LineInfo
|
||||
|
||||
lineId, err := strconv.Atoi(bus["id"].(string))
|
||||
if err != nil {
|
||||
Log.Printf("WARN: Failed to parse vehicle for stationId=%v\n\t%v", id, err)
|
||||
continue
|
||||
}
|
||||
lineInfo.Id = lineId
|
||||
|
||||
lineName, ok := bus["line_number"].(string)
|
||||
if !ok {
|
||||
lineName = ""
|
||||
|
Loading…
x
Reference in New Issue
Block a user