feat: include line id in LineInfo

This commit is contained in:
2023-09-29 00:52:36 +02:00
parent acac91dbfa
commit bcfeabc9c1
2 changed files with 30 additions and 21 deletions

BIN
main/main

Binary file not shown.

View File

@@ -3,49 +3,51 @@ package scraper
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"log"
"net/http" "net/http"
"strconv" "strconv"
"strings" "strings"
"time" "time"
"log"
) )
type Coords struct { type Coords struct {
Lat, Lon float64 Lat float64 `json:"lat"`
Lon float64 `json:"lon"`
} }
type Vehicle struct { type Vehicle struct {
GarageId string GarageId string `json:"garageId"`
Coords Coords Coords Coords `json:"coords"`
AtStationId int AtStationId int `json:"atStationId"`
AtStationName string AtStationName string `json:"atStationName"`
} }
type StationInfo struct { type StationInfo struct {
Id int Id int `json:"id"`
CityId int CityId int `json:"cityId"`
CityName string CityName string `json:"cityName"`
Name string Name string `json:"name"`
Coords Coords Coords Coords `json:"coords"`
} }
type LineInfo struct { type LineInfo struct {
Name string Id int `json:"id"`
Title string Name string `json:"name"`
Stations []StationInfo Title string `json:"title"`
Route []Coords Stations []StationInfo `json:"stations"`
Route []Coords `json:"route"`
} }
type ScrapeResult struct { type ScrapeResult struct {
Id int Id int `json:"id"`
Success bool Success bool `json:"success"`
SecondsLeft int SecondsLeft int `json:"secondsLeft"`
LineInfo LineInfo LineInfo LineInfo `json:"lineInfo"`
Vehicles []Vehicle Vehicles []Vehicle `json:"vehicles"`
} }
type Station struct { type Station struct {
Id int Id int `json:"id"`
} }
var Log = log.Default() var Log = log.Default()
@@ -139,6 +141,13 @@ func Scrape(stations []Station, c ApiConfig) ([]ScrapeResult, error) {
var lineInfo LineInfo 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) lineName, ok := bus["line_number"].(string)
if !ok { if !ok {
lineName = "" lineName = ""