Beispiel #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)
Beispiel #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)
def cn_to_cca2(country_name):
    if country_name == "Bosnia":
        return "ba"
    elif country_name == "Brunei":
        return "bn"
    elif country_name == "Congo Dem. Rep.":
        return 'cd'
    elif country_name == 'Congo Rep.':
        return 'cg'
    elif country_name == 'Guinea Bissau':
        return 'gw'
    elif country_name == 'Korea Dem. Rep.':
        return 'kp'
    elif country_name == 'Korea Rep.':
        return 'kr'
    elif country_name == 'Kyrgyzstan':
        return 'kg'
    elif country_name == 'Lao PDR':
        return 'la'
    elif country_name == 'Libya':
        return 'ly'
    elif country_name == 'Macao China':
        return 'mo'
    elif country_name == 'Macedonia FYR':
        return 'mk'
    elif country_name == 'Slovakia':
        return 'sk'
    elif country_name == 'St. Lucia':
        return 'lc'
    elif country_name == 'St. Vincent and the Grenadines':
        return 'vc'
    elif country_name == 'United Kingdom':
        return 'gb'
    elif country_name == 'United States':
        return 'us'
    elif country_name == 'West Bank and Gaza':
        return 'ps'
    elif country_name == 'Yugoslavia':
        return 'yu'
    return transformations.ccn_to_cca2( transformations.cn_to_ccn(country_name) ).lower()