diff --git a/go.mod b/go.mod index 50e21f3..77e8c93 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 1260dfd..c737e1f 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/main_test.go b/main_test.go index c97348e..c7eb0c8 100644 --- a/main_test.go +++ b/main_test.go @@ -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, diff --git a/velov.go b/velov.go index 88def09..7a49b4f 100644 --- a/velov.go +++ b/velov.go @@ -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) +}