mirror of
https://github.com/Crocmagnon/lyon-transports.git
synced 2024-11-22 05:58:06 +01:00
beautify velov station name
This commit is contained in:
parent
aa7fbeee5b
commit
4ec08222cc
4 changed files with 16 additions and 2 deletions
1
go.mod
1
go.mod
|
@ -6,6 +6,7 @@ require (
|
||||||
github.com/carlmjohnson/requests v0.24.2
|
github.com/carlmjohnson/requests v0.24.2
|
||||||
github.com/danielgtaylor/huma/v2 v2.22.1
|
github.com/danielgtaylor/huma/v2 v2.22.1
|
||||||
github.com/jarcoal/httpmock v1.3.1
|
github.com/jarcoal/httpmock v1.3.1
|
||||||
|
golang.org/x/text v0.18.0
|
||||||
gotest.tools/v3 v3.5.1
|
gotest.tools/v3 v3.5.1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
2
go.sum
2
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=
|
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 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
|
||||||
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
|
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/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 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|
|
@ -121,7 +121,7 @@ func TestGetVelovStation(t *testing.T) {
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
||||||
assert.DeepEqual(t, station, Station{
|
assert.DeepEqual(t, station, Station{
|
||||||
Name: "10039 - BOUVIER",
|
Name: "Bouvier",
|
||||||
BikesAvailable: 9,
|
BikesAvailable: 9,
|
||||||
DocksAvailable: 7,
|
DocksAvailable: 7,
|
||||||
AvailabilityCode: 1,
|
AvailabilityCode: 1,
|
||||||
|
|
13
velov.go
13
velov.go
|
@ -5,7 +5,10 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/carlmjohnson/requests"
|
"github.com/carlmjohnson/requests"
|
||||||
|
"golang.org/x/text/cases"
|
||||||
|
"golang.org/x/text/language"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Station struct {
|
type Station struct {
|
||||||
|
@ -41,7 +44,7 @@ func getStation(ctx context.Context, client *http.Client, stationID int) (*Stati
|
||||||
|
|
||||||
for _, sInfo := range info.Values {
|
for _, sInfo := range info.Values {
|
||||||
if sInfo.Number == stationID {
|
if sInfo.Number == stationID {
|
||||||
station.Name = sInfo.Name
|
station.Name = formatName(sInfo.Name)
|
||||||
station.BikesAvailable = sInfo.AvailableBikes
|
station.BikesAvailable = sInfo.AvailableBikes
|
||||||
station.DocksAvailable = sInfo.AvailableBikeStands
|
station.DocksAvailable = sInfo.AvailableBikeStands
|
||||||
station.AvailabilityCode = sInfo.AvailabilityCode
|
station.AvailabilityCode = sInfo.AvailabilityCode
|
||||||
|
@ -55,3 +58,11 @@ func getStation(ctx context.Context, client *http.Client, stationID int) (*Stati
|
||||||
|
|
||||||
return &station, nil
|
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)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue