feat: include line id in LineInfo

This commit is contained in:
dvdrw 2023-09-29 00:52:36 +02:00
parent acac91dbfa
commit bcfeabc9c1
Signed by: dvdrw
GPG Key ID: 4756FA53D8797D7F
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 (
"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 = ""