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 {
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)

View file

@ -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"),

View file

@ -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)