Skip to content

Instantly share code, notes, and snippets.

@thomas-maschler
Created October 18, 2016 23:08
Show Gist options
  • Save thomas-maschler/dd34795fd5def1315b0a2dd6e3dd9edd to your computer and use it in GitHub Desktop.
Save thomas-maschler/dd34795fd5def1315b0a2dd6e3dd9edd to your computer and use it in GitHub Desktop.
import osmapi
# Connect to OSM
api = osmapi.OsmApi(username="osm-user", password="***")
# Create a new changeset
api.ChangesetCreate({u"comment": u"updating abandoned roads"})
# Read File with way id and highway dates
with open("East_Complex_Attributes.txt", "r") as f:
for row in f:
# Extract values for row
values = row.split(",")
nid = int(values[0].strip())
time1 = values[1].strip()
time2 = values[2].strip()
print nid
way = api.WayGet(nid)
# If Way exists
if way is not None:
print way
# Remove timestamp tag for later update
way.pop(u'timestamp')
# Add highway dates
way[u"tag"][u"highway:{}".format(time1)] = u"track"
if len(time2):
way[u"tag"][u"highway:{}".format(time2)] = u"track"
# Update Way
api.WayUpdate(way)
# If way doesn't exist
else:
print "skip"
# Close Changeset
api.ChangesetClose()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment