-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupload.py
72 lines (67 loc) · 2.41 KB
/
upload.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# -*- coding: utf-8 -*-
import osmapi
import sys
import csv
import json
userName = sys.argv[1]
userPassword = sys.argv[2]
inputFile = sys.argv[3]
inputLanguage = sys.argv[4]
log = sys.argv[5]
api = osmapi.OsmApi(api="api06.dev.openstreetmap.org", username = userName, password = userPassword)
api.ChangesetCreate({u"comment": u"adding kn name tags"})
def get_osm_type (osm_id, osm_type):
if osm_type == 'node':
node = api.NodeGet(int(osm_id))
return node
elif osm_type == 'way':
way = api.WayGet(int(osm_id))
return way
elif osm_type == 'relation':
relation = api.RelationGet(osm_id)
return relation
else:
print "invalid type %s" % osm_type
def osm_upload (osm_type, osm_object):
if osm_type == 'node':
node = api.NodeUpdate(osm_object)
return node
elif osm_type == 'way':
way = api.WayUpdate(osm_object)
return way
elif osm_type == 'relation':
relation = api.RelationUpdate(osm_object)
return relation
with open(inputFile, 'r') as csvfile:
logFile = open(log, 'w')
rows = csv.reader(csvfile, delimiter=',')
i = 0
for row in rows:
if i == 0:
i = i+1
continue
osm_id = row[0]
osm_type = str(row[1])
translation = str(row[2]).strip('\n')
translation = translation.decode('utf-8')
try:
typeContent = get_osm_type (osm_id, osm_type)
if ('name:'+ inputLanguage in typeContent['tag']):
osmContent = typeContent['tag']['name:'+ inputLanguage]
if osmContent == translation:
print (osmContent, translation)
print ('Translation present in OpenStreetMap')
logFile.write('Translation present in OSM' + '\n')
else:
print (osmContent, translation)
print ('MisMatched Translation in OpenStreetMap')
logFile.write('MisMatched Translation in OpenStreetMap' +'\n')
else:
typeContent['tag']['name:'+ inputLanguage] = translation
osm_upload(osm_type, typeContent)
print ('Uploaded new translation to OpenStreetMap')
logFile.write('Uploaded new translation to OpenStreetMap' + '\n')
except ValueError:
print "ValueError occurred"
continue
api.ChangesetClose()