Example #1
0
    def __init__(self, key):
        """Infer the country from the key
        
        Valid keys are: two letter, three letter or numeric country code
        acording to ISO 3166 or the countries simple English name.

        Raises ValueError if key is not found.
        """

        if key in data.cn_to_ccn:
            self.cn = self.name = key
            self.ccn = self.numeric = data.cn_to_ccn[key]
        else:
            try:
                code = trafos.cc_to_ccn(key)
            except KeyError:
                raise ValueError("%s is o ISO country code or name" % key)
            self.ccn = self.numeric = code
            self.cn = self.name = trafos.ccn_to_cn(self.ccn)

        self.cca2 = self.alpha2 = trafos.ccn_to_cca2(self.numeric)
        self.cca3 = self.alpha3 = trafos.ccn_to_cca3(self.numeric)
        self.con = self.official_name = trafos.ccn_to_con(self.numeric)

        self.ctca2 = trafos.ccn_to_ctca2(self.numeric)
        self.ctn = trafos.ccn_to_ctn(self.numeric)
Example #2
0
    def __init__(self, key):
        """Infer the country from the key

        Valid keys are: two letter, three letter or numeric country code
        acording to ISO 3166 or the countries simple English name.

        Raises ValueError if key is not found.
        """

        if key in data.cn_to_ccn:
            self.cn = self.name = key
            self.ccn = self.numeric = data.cn_to_ccn[key]
        else:
            try:
                code = trafos.cc_to_ccn(key)
            except KeyError:
                raise ValueError("%s is o ISO country code or name" % key)
            self.ccn = self.numeric = code
            self.cn = self.name = trafos.ccn_to_cn(self.ccn)

        self.cca2 = self.alpha2 = trafos.ccn_to_cca2(self.numeric)
        self.cca3 = self.alpha3 = trafos.ccn_to_cca3(self.numeric)
        self.con = self.official_name = trafos.ccn_to_con(self.numeric)

        self.ctca2 = trafos.ccn_to_ctca2(self.numeric)
        self.ctn = trafos.ccn_to_ctn(self.numeric)
Example #3
0
    def process(self, ctx, m):

        data = ctx.interpolate(self.data, m)

        m[self.prefix + "country_code"] = self._gi.country_code_by_addr(data)
        m[self.prefix + "country_name"] = self._gi.country_name_by_addr(
            data)  #.decode("latin1")
        m[self.prefix + "cont_name"] = None

        if m[self.prefix + "country_code"]:
            try:
                m[self.prefix + "cont_name"] = transformations.ccn_to_ctn(
                    transformations.cca2_to_ccn(
                        m[self.prefix + "country_code"]))  #.decode("latin1")
            except Exception as e:
                if not self._extract_error and not ctx.debug2:
                    self._extract_error = True
                    logger.warning(
                        "Could not extract continent name from country code '%s' (reported only once per run) Error: %s"
                        % (m[self.prefix + "country_code"], e))

        #gir = self._gi.region_by_addr(data)
        #m["geo_region_code"] = gir['region']
        #m["geo_region_name"] = gir['region_name']

        yield m
Example #4
0
    def process(self, ctx, m):

        data = ctx.interpolate(self.data, m)

        m[self.prefix + "country_code"] = self._gi.country_code_by_addr(data)
        m[self.prefix + "country_name"] = self._gi.country_name_by_addr(data) #.decode("latin1")
        m[self.prefix + "cont_name"] = None

        if m[self.prefix + "country_code"]:
            try:
                m[self.prefix + "cont_name"] = transformations.ccn_to_ctn(transformations.cca2_to_ccn(m[self.prefix + "country_code"])) #.decode("latin1")
            except Exception as e:
                if not self._extract_error and not ctx.debug2:
                    self._extract_error = True
                    logger.warning("Could not extract continent name from country code '%s' (reported only once per run) Error: %s" % (m[self.prefix + "country_code"], e))

        #gir = self._gi.region_by_addr(data)
        #m["geo_region_code"] = gir['region']
        #m["geo_region_name"] = gir['region_name']

        yield m