From 28d29b7ce5cdc29baadcf797ef0858566f0ac888 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 29 Jun 2020 13:34:26 +0000 Subject: [PATCH] importer: Write NULL into database when bool is not set Signed-off-by: Michael Tremer --- src/python/location-importer.in | 34 +++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/python/location-importer.in b/src/python/location-importer.in index 05324b7..63df5e8 100644 --- a/src/python/location-importer.in +++ b/src/python/location-importer.in @@ -649,9 +649,9 @@ class CLI(object): ON CONFLICT (network) DO NOTHING""", "%s" % network, block.get("country"), - block.get("is-anonymous-proxy") == "yes", - block.get("is-satellite-provider") == "yes", - block.get("is-anycast") == "yes", + self._parse_bool(block, "is-anonymous-proxy"), + self._parse_bool(block, "is-satellite-provider"), + self._parse_bool(block, "is-anycast"), ) elif type == "aut-num": @@ -678,14 +678,36 @@ class CLI(object): autnum, block.get("name"), block.get("country"), - block.get("is-anonymous-proxy") == "yes", - block.get("is-satellite-provider") == "yes", - block.get("is-anycast") == "yes", + self._parse_bool(block, "is-anonymous-proxy"), + self._parse_bool(block, "is-satellite-provider"), + self._parse_bool(block, "is-anycast"), ) else: log.warning("Unsupport type: %s" % type) + @staticmethod + def _parse_bool(block, key): + val = block.get(key) + + # There is no point to proceed when we got None + if val is None: + return + + # Convert to lowercase + val = val.lower() + + # True + if val in ("yes", "1"): + return True + + # False + if val in ("no", "0"): + return False + + # Default to None + return None + def handle_import_countries(self, ns): with self.db.transaction(): # Drop all data that we have -- 2.39.5