added replacePlaceNames function
This commit is contained in:
parent
89221c78b6
commit
703d433788
42
utils.py
42
utils.py
|
@ -106,6 +106,48 @@ def dumpUnknownPlaces():
|
|||
out.close()
|
||||
return result
|
||||
|
||||
def replacePlaceNames(old, new, operator="", start=0, end=100):
|
||||
matchedPlaces = findAnnotations(old, 'places', operator, start, end)
|
||||
logFile = open("replacedPlacesLog.txt", "a")
|
||||
ret = []
|
||||
for m in matchedPlaces:
|
||||
value = m['value']
|
||||
new_value = value.replace(old, new).strip()
|
||||
ret.append(api.editAnnotation({
|
||||
'id': m['id'],
|
||||
'in': m['in'],
|
||||
'out': m['out'],
|
||||
'value': new_value
|
||||
}))
|
||||
log = "%s| %s| %s" % (m['id'], value, new_value,)
|
||||
logFile.write(log + "\n")
|
||||
print log
|
||||
logFile.close()
|
||||
return ret
|
||||
|
||||
|
||||
def findAnnotations(value, layer, operator="", start=0, end=500):
|
||||
result = api.findAnnotations({
|
||||
'query': {
|
||||
'conditions': [
|
||||
{
|
||||
'key': 'layer',
|
||||
'value': layer,
|
||||
'operator': '='
|
||||
},
|
||||
{
|
||||
'key': 'value',
|
||||
'value': value,
|
||||
'operator': operator
|
||||
}
|
||||
],
|
||||
'operator': '&'
|
||||
},
|
||||
'keys': [],
|
||||
'range': [start, end]
|
||||
})
|
||||
return result['data']['items']
|
||||
|
||||
|
||||
def dumpKnownPlaces():
|
||||
result = api.findPlaces({
|
||||
|
|
Loading…
Reference in New Issue
Block a user