1
0
Fork 0
mirror of https://github.com/Luzifer/gpxhydrant.git synced 2024-11-08 15:30:00 +00:00

Update program version / comment on every run

This commit is contained in:
Knut Ahlers 2016-05-07 14:49:53 +02:00
parent 8a18e2454b
commit 8a1341a462
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
2 changed files with 31 additions and 4 deletions

13
main.go
View file

@ -27,7 +27,7 @@ var (
UseDev bool `flag:"osm-dev" default:"false" description:"Switch to dev API"`
}
MachRange int64 `flag:"match-range" default:"20" description:"Range of meters to match GPX hydrants to OSM nodes"`
Comment string `flag:"comment,c" description:"Comment for the changeset"`
Comment string `flag:"comment,c" default:"Added hydrants from GPX file" description:"Comment for the changeset"`
}{}
version = "dev"
@ -233,7 +233,7 @@ func main() {
if len(changeSets) > 0 {
cs = changeSets[0]
} else {
cs, err = osmClient.CreateChangeset(cfg.Comment)
cs, err = osmClient.CreateChangeset()
if err != nil {
log.Fatalf("Unable to create changeset: %s", err)
}
@ -243,6 +243,15 @@ func main() {
log.Printf("Working on Changeset %d", cs.ID)
}
cs.Tags = []osm.Tag{
{Key: "comment", Value: cfg.Comment},
{Key: "created_by", Value: fmt.Sprintf("gpxhydrant %s", version)},
}
if err := osmClient.SaveChangeset(cs); err != nil {
log.Fatalf("Unable to save changeset: %s", err)
}
border := 0.0009 // Equals ~100m using haversine formula
mapData, err := osmClient.RetrieveMapObjects(minLon-border, minLat-border, maxLon+border, maxLat+border)
if err != nil {

View file

@ -12,7 +12,7 @@ import (
)
const (
liveAPIBaseURL = "http://api.openstreetmap.org/api/0.6"
liveAPIBaseURL = "http://api-openstreetmap-org-ue6z91hlm5oj.runscope.net/api/0.6" // "http://api.openstreetmap.org/api/0.6"
devAPIBaseURL = "http://api06.dev.openstreetmap.org/api/0.6"
)
@ -129,7 +129,7 @@ func (c *Client) GetMyChangesets(onlyOpen bool) ([]*Changeset, error) {
return r.Changesets, c.doParse("GET", urlPath, nil, r)
}
func (c *Client) CreateChangeset(comment string) (*Changeset, error) {
func (c *Client) CreateChangeset() (*Changeset, error) {
body := bytes.NewBuffer([]byte{})
if err := xml.NewEncoder(body).Encode(Wrap{Changesets: []*Changeset{{}}}); err != nil {
return nil, err
@ -152,6 +152,24 @@ func (c *Client) CreateChangeset(comment string) (*Changeset, error) {
return cs.Changesets[0], nil
}
func (c *Client) SaveChangeset(cs *Changeset) error {
urlPath := "/changeset/create"
if cs.ID > 0 {
urlPath = fmt.Sprintf("/changeset/%d", cs.ID)
}
data := Wrap{Changesets: []*Changeset{cs}}
body := bytes.NewBuffer([]byte{})
if err := xml.NewEncoder(body).Encode(data); err != nil {
return err
}
_, err := c.doPlain("PUT", urlPath, body)
return err
}
func (c *Client) RetrieveMapObjects(minLat, minLon, maxLat, maxLon float64) (*Wrap, error) {
urlPath := fmt.Sprintf("/map?bbox=%.7f,%.7f,%.7f,%.7f", minLat, minLon, maxLat, maxLon)
res := &Wrap{}