]> git.ipfire.org Git - location/location-database.git/commitdiff
Import
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 15 Oct 2019 14:54:55 +0000 (14:54 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 15 Oct 2019 14:54:55 +0000 (14:54 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
compile-database
tools/database.py

index 01c12e80ae09e3b8893ff86b7977234ac16d6b2c..6dc82d2ab8a9dd47fda47d29230929105d1243be 100755 (executable)
@@ -31,6 +31,11 @@ if not len(sys.argv) > 1:
 path = sys.argv[1]
 
 database = tools.Database(vendor="IPFire Project")
+
+# Import countries
+database.import_countries("countries.txt")
+
+# Import all RIRs
 for RIR in tools.RIRS:
        rir = RIR()
 
index 8ad61c58d628373399c2e3c045babecbe882e2ff..823faaf6eb1e29d0230fa727df3e78426da26381 100644 (file)
@@ -20,6 +20,7 @@
 #                                                                             #
 ###############################################################################
 
+import iso3166
 import logging
 import re
 
@@ -108,3 +109,26 @@ class Database(object):
                                n.asn = asn
 
                        logging.debug("Added new network: %s" % n)
+
+       def import_countries(self, filename):
+               with open(filename) as f:
+                       for line in f:
+                               if line.startswith("#"):
+                                       continue
+
+                               try:
+                                       country_code, continent_code = line.split()
+                               except:
+                                       logging.error("Could not parse line in %s: %s" (filename, line))
+                                       raise
+
+                               c = self.writer.add_country(country_code)
+
+                               # Add continent code
+                               if continent_code:
+                                       c.continent_code = continent_code
+
+                               # Add name
+                               country = iso3166.countries_by_alpha2.get(country_code)
+                               if country:
+                                       c.name = country.apolitical_name