diff --git a/img.go b/img.go index d8935a5..aafb83c 100644 --- a/img.go +++ b/img.go @@ -28,6 +28,10 @@ func getBlack( if err != nil { return nil, fmt.Errorf("getting tram: %w", err) } + velovRoc, err := transportsClient.GetVelovStation(ctx, 10044) + if err != nil { + return nil, fmt.Errorf("getting velov: %w", err) + } fetes, err := feteClient.GetFete(ctx, nowFunc()) if err != nil { @@ -48,11 +52,19 @@ func getBlack( drawTCL(gc, bus, 30) drawTCL(gc, tram, 150) + drawVelov(gc, velovRoc, 290) drawDateFete(gc, fetes, nowFunc()) return img, nil } +func drawVelov(gc *draw2dimg.GraphicContext, station *transports.Station, yOffset float64) { + x := float64(600) + text(gc, station.Name, 15, x, yOffset) + text(gc, fmt.Sprintf("V : %v - P : %v", station.BikesAvailable, station.DocksAvailable), 15, x, yOffset+30) + //text(gc, fmt.Sprintf("P : %v", station.DocksAvailable), 15, x, yOffset+60) +} + func drawDateFete(gc *draw2dimg.GraphicContext, fetes *fete.Fete, now time.Time) { text(gc, now.Format("15:04"), 40, 20, 190) text(gc, getDate(now), 50, 20, 255) diff --git a/main.go b/main.go index e145385..8b5a25b 100644 --- a/main.go +++ b/main.go @@ -27,9 +27,7 @@ func main() { fontCache.Store(draw2d.FontData{Name: fontName}, font) draw2d.SetFontCache(fontCache) - transportsClient := transports.New(nil, transports.Config{ - Authorization: os.Getenv("TRANSPORTS_AUTHORIZATION"), - }) + transportsClient := transports.New(nil, transports.Config{}) feteClient := fete.New(nil, fete.Config{ APIKey: os.Getenv("FETE_API_KEY"), diff --git a/transports/transports.go b/transports/transports.go index 538430c..dcbd741 100644 --- a/transports/transports.go +++ b/transports/transports.go @@ -24,7 +24,6 @@ type Passages struct { } type Config struct { - Authorization string } type Client struct { @@ -44,8 +43,26 @@ func New(httpClient *http.Client, config Config) *Client { func (c *Client) GetTCLPassages(ctx context.Context, stop int) (res *Passages, err error) { err = requests.URL("https://tcl.augendre.info"). - Pathf("/stop/%v", stop). - Header("Authorization", c.config.Authorization). + Pathf("/tcl/stop/%v", stop). + Client(c.client). + ToJSON(&res). + Fetch(ctx) + if err != nil { + return nil, fmt.Errorf("calling api: %w", err) + } + return res, nil +} + +type Station struct { + Name string `json:"name"` + BikesAvailable int `json:"bikes_available"` + DocksAvailable int `json:"docks_available"` + AvailabilityCode int `json:"availability_code"` +} + +func (c *Client) GetVelovStation(ctx context.Context, station int) (res *Station, err error) { + err = requests.URL("https://tcl.augendre.info"). + Pathf("/velov/station/%v", station). Client(c.client). ToJSON(&res). Fetch(ctx)