beautify velov station name

This commit is contained in:
Gabriel Augendre 2024-09-15 14:14:05 +02:00
parent aa7fbeee5b
commit 4ec08222cc
4 changed files with 16 additions and 2 deletions

1
go.mod
View file

@ -6,6 +6,7 @@ require (
github.com/carlmjohnson/requests v0.24.2
github.com/danielgtaylor/huma/v2 v2.22.1
github.com/jarcoal/httpmock v1.3.1
golang.org/x/text v0.18.0
gotest.tools/v3 v3.5.1
)

2
go.sum
View file

@ -28,6 +28,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View file

@ -121,7 +121,7 @@ func TestGetVelovStation(t *testing.T) {
assert.NilError(t, err)
assert.DeepEqual(t, station, Station{
Name: "10039 - BOUVIER",
Name: "Bouvier",
BikesAvailable: 9,
DocksAvailable: 7,
AvailabilityCode: 1,

View file

@ -5,7 +5,10 @@ import (
"errors"
"fmt"
"github.com/carlmjohnson/requests"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"net/http"
"strings"
)
type Station struct {
@ -41,7 +44,7 @@ func getStation(ctx context.Context, client *http.Client, stationID int) (*Stati
for _, sInfo := range info.Values {
if sInfo.Number == stationID {
station.Name = sInfo.Name
station.Name = formatName(sInfo.Name)
station.BikesAvailable = sInfo.AvailableBikes
station.DocksAvailable = sInfo.AvailableBikeStands
station.AvailabilityCode = sInfo.AvailabilityCode
@ -55,3 +58,11 @@ func getStation(ctx context.Context, client *http.Client, stationID int) (*Stati
return &station, nil
}
func formatName(name string) string {
nameParts := strings.SplitN(name, " - ", 2)
if len(nameParts) >= 2 {
name = nameParts[1]
}
return cases.Title(language.French).String(name)
}