How to use the pycountry.subdivisions.get function in pycountry

To help you get started, we’ve selected a few pycountry examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Pinafore / qb / qanta / guesser / rnn_entity.py View on Github external
', ftp,'
    'ftp,',
    'ftp',
    '(*)'
}
re_pattern = '|'.join([re.escape(p) for p in qb_patterns])
re_pattern += r'|\[.*?\]|\(.*?\)'

COUNTRIES = {'american'}
for c in pycountry.countries:
    split = c.name.lower().split()
    if len(split) == 1:
        COUNTRIES.add(split[0])

STATES = set()
for s in pycountry.subdivisions.get(country_code='US'):
    if s.type == 'State':
        split = s.name.lower().split()
        if len(split) == 1:
            STATES.add(split[0])

NN_TAGS = {'NN', 'NNP', 'NNS'}
SKIP_PUNCTATION = {'HYPH', 'POS'}
SKIP_TAGS = NN_TAGS | SKIP_PUNCTATION
PRONOUNS = {'they', 'it', 'he', 'she'}
PREPOSITION_POS = {'ADP', 'ADV'}


def extract_this_mentions(tokens):
    begin = None
    mention_spans = []
    i = 0
github benbest86 / myewb2 / myewb / apps / stats / views.py View on Github external
yaxis = range(0, max(chaptermembers), 10)
    yaxis[0] = ''
    membershipBreakdownChart.set_axis_labels(Axis.BOTTOM, yaxis)
    membershipBreakdownChart.set_axis_labels(Axis.LEFT,
                                             chapternames)
    membershipBreakdownChart.set_bar_width(330 / len(chapternames))
    membershipBreakdown = membershipBreakdownChart.get_url()
    
    # ---- Province breakdown ----
    profiletype = ContentType.objects.get_for_model(MemberProfile)
    addresses = Address.objects.filter(content_type=profiletype)
    totalprov = Address.objects.filter(content_type=profiletype).count() + 1     # FIXME
    
    provinces = []
    provincecount = []
    provincelist = list(pycountry.subdivisions.get(country_code='CA'))
    for p in provincelist:
        pcode = p.code.split('-')[1]
        provincecount2 = Address.objects.filter(content_type=profiletype,
                                                province=pcode).count()
        if provincecount2 == 0:
            provincecount2 = 1
        provincecount.append(provincecount2)                                
        provinces.append(pcode + " (%d%%)" % (provincecount2*100/totalprov))
    #provinces = sorted(provinces)
    
    provinceBreakdownChart = PieChart3D(600, 240)
    provinceBreakdownChart.add_data(provincecount)

    #provinceBreakdownChart.set_colours(['ff0000', 'ffff00', '00ff00'])
    provinceBreakdownChart.set_pie_labels(provinces)
    provinceBreakdown = provinceBreakdownChart.get_url()
github mikelambert / dancedeets-monorepo / server / dancedeets / events / event_locations.py View on Github external
def state_name_for_fb_location(location):
    state_name = location.get('state')
    try:
        country = pycountry.countries.get(name=location.get('country'))
        state = pycountry.subdivisions.get(code='%s-%s' % (country.alpha_2, location.get('state')))
        if state:
            state_name = state.name
    except KeyError:
        pass
    return state_name
github HaliteChallenge / Halite-III / apiserver / apiserver / web / util.py View on Github external
def validate_country(country_code, subdivision_code):
    try:
        country = pycountry.countries.get(alpha_3=country_code)
    except KeyError:
        return False

    if subdivision_code:
        subdivisions = pycountry.subdivisions.get(country_code=country.alpha_2)
        for subdivision in subdivisions:
            if subdivision.code == subdivision_code:
                return True
        return False
    else:
        return True
github scaleway / postal-address / postal_address / address.py View on Github external
:param required_fields:
        :return:
        """
        invalid_fields = dict()
        if 'country_code' not in required_fields:
            # Check that the country code exists.
            try:
                countries.get(alpha_2=self.country_code)
            except KeyError:
                invalid_fields['country_code'] = self.country_code

        if self.subdivision_code and 'subdivision_code' not in required_fields:
            # Check that the country code exists.
            try:
                subdivisions.get(code=self.subdivision_code)
            except KeyError:
                invalid_fields['subdivision_code'] = self.subdivision_code
        return invalid_fields
github ushahidi / geograpy / geograpy / places.py View on Github external
def get_region_names(self, country_name):
        country_name = self.correct_country_mispelling(country_name)
        try:
            obj = pycountry.countries.get(name=country_name)
            regions = pycountry.subdivisions.get(country_code=obj.alpha2)
        except:
            regions = []

        return [r.name for r in regions]
github pretix / pretix / src / pretix / base / forms / questions.py View on Github external
super().__init__(*args, **kwargs)
        if not event.settings.invoice_address_vatid:
            del self.fields['vat_id']

        c = [('', pgettext_lazy('address', 'Select state'))]
        fprefix = self.prefix + '-' if self.prefix else ''
        cc = None
        if fprefix + 'country' in self.data:
            cc = str(self.data[fprefix + 'country'])
        elif 'country' in self.initial:
            cc = str(self.initial['country'])
        elif self.instance and self.instance.country:
            cc = str(self.instance.country)
        if cc and cc in COUNTRIES_WITH_STATE_IN_ADDRESS:
            types, form = COUNTRIES_WITH_STATE_IN_ADDRESS[cc]
            statelist = [s for s in pycountry.subdivisions.get(country_code=cc) if s.type in types]
            c += sorted([(s.code[3:], s.name) for s in statelist], key=lambda s: s[1])
        elif fprefix + 'state' in self.data:
            self.data = self.data.copy()
            del self.data[fprefix + 'state']

        self.fields['state'] = forms.ChoiceField(
            label=pgettext_lazy('address', 'State'),
            required=False,
            choices=c,
            widget=forms.Select(attrs={
                'autocomplete': 'address-level1',
            }),
        )
        self.fields['state'].widget.is_required = True

        if not event.settings.invoice_address_required or self.all_optional: