first commit
This commit is contained in:
commit
2eed16376f
4 changed files with 107 additions and 0 deletions
2
1856337628.gpx
Normal file
2
1856337628.gpx
Normal file
File diff suppressed because one or more lines are too long
10
go.mod
Normal file
10
go.mod
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
module git.readonly.ch/bouzoure/gpx-downloader
|
||||||
|
|
||||||
|
go 1.25.7
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/golang-io/requests v0.0.0-20260112012319-11ff3d588020 // indirect
|
||||||
|
github.com/tkrajina/gpxgo v1.4.0 // indirect
|
||||||
|
golang.org/x/net v0.50.0 // indirect
|
||||||
|
golang.org/x/text v0.34.0 // indirect
|
||||||
|
)
|
||||||
20
go.sum
Normal file
20
go.sum
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/golang-io/requests v0.0.0-20260112012319-11ff3d588020 h1:NsY7l0CzD6sL4YDmi2ug1XJ2syK6HYtE4Vu38+S59Kc=
|
||||||
|
github.com/golang-io/requests v0.0.0-20260112012319-11ff3d588020/go.mod h1:axo3gO6bWOpJNUipkqkmAH7WwdeLg5phLVI3N1dFBnM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/tkrajina/gpxgo v1.4.0 h1:cSD5uSwy3VZuNFieTEZLyRnuIwhonQEkGPkPGW4XNag=
|
||||||
|
github.com/tkrajina/gpxgo v1.4.0/go.mod h1:BXSMfUAvKiEhMEXAFM2NvNsbjsSvp394mOvdcNjettg=
|
||||||
|
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
|
golang.org/x/net v0.50.0 h1:ucWh9eiCGyDR3vtzso0WMQinm2Dnt8cFMuQa9K33J60=
|
||||||
|
golang.org/x/net v0.50.0/go.mod h1:UgoSli3F/pBgdJBHCTc+tp3gmrU4XswgGRgtnwWTfyM=
|
||||||
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
|
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
|
||||||
|
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
75
main.go
Normal file
75
main.go
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/golang-io/requests"
|
||||||
|
"github.com/tkrajina/gpxgo/gpx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SuisseMobileGeometry struct {
|
||||||
|
Segments [][][]float64 `json:"coordinates"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SuisseMobileProperties struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SuisseMobileResponse struct {
|
||||||
|
Properties SuisseMobileProperties `json:"properties"`
|
||||||
|
Geometry SuisseMobileGeometry `json:"geometry"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
sess := requests.New(requests.URL("https://schweizmobil.ch"))
|
||||||
|
resp, _ := sess.DoRequest(context.Background(),
|
||||||
|
requests.Path("/api/6/tracks/1856337628"),
|
||||||
|
)
|
||||||
|
|
||||||
|
var response SuisseMobileResponse
|
||||||
|
err := json.Unmarshal(resp.Content.Bytes(), &response)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var gpxFile gpx.GPX
|
||||||
|
var gpxTrack gpx.GPXTrack
|
||||||
|
|
||||||
|
gpxFile.Name = response.Properties.Name
|
||||||
|
|
||||||
|
for _, segments := range response.Geometry.Segments {
|
||||||
|
var gpxTrackSegment gpx.GPXTrackSegment
|
||||||
|
|
||||||
|
for _, point := range segments {
|
||||||
|
fmt.Println(point)
|
||||||
|
var gpxPoint gpx.GPXPoint
|
||||||
|
|
||||||
|
gpxPoint.Longitude = point[0]
|
||||||
|
gpxPoint.Latitude = point[1]
|
||||||
|
gpxPoint.Elevation = *gpx.NewNullableFloat64(point[2])
|
||||||
|
|
||||||
|
gpxTrackSegment.AppendPoint(&gpxPoint)
|
||||||
|
}
|
||||||
|
|
||||||
|
gpxTrack.AppendSegment(&gpxTrackSegment)
|
||||||
|
}
|
||||||
|
|
||||||
|
gpxFile.AppendTrack(&gpxTrack)
|
||||||
|
xml, err := gpxFile.ToXml(gpx.ToXmlParams{})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
file, err := os.Create("1856337628.gpx")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = file.Write(xml)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue