]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
importer: Silently ignore any empty country codes in Geofeeds
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 4 Jul 2023 09:36:50 +0000 (09:36 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 4 Jul 2023 09:36:50 +0000 (09:36 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/scripts/location-importer.in

index 547ff610ec56622cf64742c72119b81e0eaa4d1e..4a54aae8d63a96079f53c8236e6d0ca9e55b83bd 100644 (file)
@@ -1319,8 +1319,12 @@ class CLI(object):
                                        self.db.execute("DELETE FROM geofeed_networks \
                                                WHERE geofeed_id = %s", geofeed.id)
 
+                                       lineno = 0
+
                                        # Read the output line by line
                                        for line in f:
+                                               lineno += 1
+
                                                line = line.decode()
 
                                                # Strip any newline
@@ -1357,7 +1361,12 @@ class CLI(object):
                                                        country = country.strip()
 
                                                # Check the country code
-                                               if not location.country_code_is_valid(country):
+                                               if not country:
+                                                       log.debug("Empty country code in Geofeed %s line %s" \
+                                                               % (geofeed.url, lineno))
+                                                       continue
+
+                                               elif not location.country_code_is_valid(country):
                                                        log.warning("Invalid country code in Geofeed %s: %s" \
                                                                % (geofeed.url, country))
                                                        continue