display velov

This commit is contained in:
Gabriel Augendre 2024-09-15 14:19:01 +02:00
parent 0bc718e3ae
commit 6b1fb30171
3 changed files with 33 additions and 6 deletions

12
img.go
View file

@ -28,6 +28,10 @@ func getBlack(
if err != nil { if err != nil {
return nil, fmt.Errorf("getting tram: %w", err) 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()) fetes, err := feteClient.GetFete(ctx, nowFunc())
if err != nil { if err != nil {
@ -48,11 +52,19 @@ func getBlack(
drawTCL(gc, bus, 30) drawTCL(gc, bus, 30)
drawTCL(gc, tram, 150) drawTCL(gc, tram, 150)
drawVelov(gc, velovRoc, 290)
drawDateFete(gc, fetes, nowFunc()) drawDateFete(gc, fetes, nowFunc())
return img, nil 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) { func drawDateFete(gc *draw2dimg.GraphicContext, fetes *fete.Fete, now time.Time) {
text(gc, now.Format("15:04"), 40, 20, 190) text(gc, now.Format("15:04"), 40, 20, 190)
text(gc, getDate(now), 50, 20, 255) text(gc, getDate(now), 50, 20, 255)

View file

@ -27,9 +27,7 @@ func main() {
fontCache.Store(draw2d.FontData{Name: fontName}, font) fontCache.Store(draw2d.FontData{Name: fontName}, font)
draw2d.SetFontCache(fontCache) draw2d.SetFontCache(fontCache)
transportsClient := transports.New(nil, transports.Config{ transportsClient := transports.New(nil, transports.Config{})
Authorization: os.Getenv("TRANSPORTS_AUTHORIZATION"),
})
feteClient := fete.New(nil, fete.Config{ feteClient := fete.New(nil, fete.Config{
APIKey: os.Getenv("FETE_API_KEY"), APIKey: os.Getenv("FETE_API_KEY"),

View file

@ -24,7 +24,6 @@ type Passages struct {
} }
type Config struct { type Config struct {
Authorization string
} }
type Client struct { 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) { func (c *Client) GetTCLPassages(ctx context.Context, stop int) (res *Passages, err error) {
err = requests.URL("https://tcl.augendre.info"). err = requests.URL("https://tcl.augendre.info").
Pathf("/stop/%v", stop). Pathf("/tcl/stop/%v", stop).
Header("Authorization", c.config.Authorization). 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). Client(c.client).
ToJSON(&res). ToJSON(&res).
Fetch(ctx) Fetch(ctx)