From 703d433788ae118f6462d893904ec7db97d3b4d8 Mon Sep 17 00:00:00 2001 From: Sanj Date: Tue, 21 Feb 2012 02:55:17 +0530 Subject: [PATCH] added replacePlaceNames function --- utils.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/utils.py b/utils.py index 874f7f8..9f48ada 100644 --- a/utils.py +++ b/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({