self.db = target_db
self.cursor = self.db.cursor()
self.dom = dom.parse(input_file)
-
+ self.known_types = []
def get_children_by_tag_name(self, node, tagName):
children = []
flat.append(n.firstChild.nodeValue.strip())
return flat
- def insert_location(self, name, type, parentName):
+ def insert_location(self, name, type, parentName, historic_names):
if type == 'CONTINENT':
short_type = 'continent'
elif type == 'BASEADM':
else:
short_type = 'other'
+ self.register_type(type)
+
self.cursor.execute("REPLACE INTO locations "+
"(name, type, complete_type_id, current_name, is_authoritative) "+
"VALUES (%s, %s, %s, %s, %s)", (name, short_type, type, name, 1))
self.nrelations += 1
- if self.nlocations % 100 == 0:
+ for hname in historic_names:
+ self.cursor.execute("REPLACE INTO locations "+
+ "(name, type, complete_type_id, current_name, is_authoritative) "+
+ "VALUES (%s, %s, %s, %s, %s)", (hname, short_type, type, name, 1))
+ self.nhistoric_names += 1
+
+
+ if self.nlocations % 1000 == 0:
sys.stdout.write('.')
sys.stdout.flush()
"VALUES (%s, %s, %s)", (name, alias, 1))
self.naliases += 1
- def add_historic_names(self, name, items):
- pass
+ def register_type(self, id):
+ try:
+ self.known_types.index(id)
+ except ValueError:
+ self.cursor.execute("REPLACE INTO location_types (id, name) "+
+ "VALUES (%s, %s)", (id,""))
+ self.known_types.append(id)
def is_empty(self, node):
for n in node.childNodes:
aliasNodes = self.get_children_by_tag_name(n, 'ALIAS')
historicNameNodes = self.get_children_by_tag_name(n, 'DESCR-HISTORIQUE')
- self.insert_location(name, type, parentName)
+ self.insert_location(name, type, parentName, self.flatten_node_list(historicNameNodes))
self.add_aliases(name, self.flatten_node_list(aliasNodes))
- self.add_historic_names(name, self.flatten_node_list(historicNameNodes))
self.process_children(n, name)
self.path.pop()
self.path = []
self.process_children(self.dom.getElementsByTagName('GEOETHNO')[0], '')
sys.stdout.write('\nGeoethno import result:\n')
+ sys.stdout.write(' types: %d\n' % len(self.known_types))
sys.stdout.write(' locations: %d\n' % self.nlocations)
sys.stdout.write(' relations: %d\n' % self.nrelations)
sys.stdout.write(' aliases: %d\n' % self.naliases)
def warn(self, msg):
- print u"\nError: %s: %s\n" % ("/".join(self.path), msg)
+ print u"\nWarning: %s: %s\n" % ("/".join(self.path), msg)
class Error(Exception):