Skip to content

Commit

Permalink
Merge pull request #12 from arslanhashmi/arslan/select-country-via-al…
Browse files Browse the repository at this point in the history
…t-name

Select a country via its alt names
  • Loading branch information
porimol authored Dec 26, 2019
2 parents 5ff8b4d + a1ce0d2 commit 54f8d5b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 35 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ country.info()
},
'wiki': 'http://en.wikipedia.org/wiki/singapore'
}

# Similar can also be achieved via country code or any
# alternate name of a country. For example, Singapur
# would be:
country = CountryInfo('SG')
```

### .provinces()
Expand Down
48 changes: 14 additions & 34 deletions countryinfo/countryinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def __init__(self, country_name=None):
# pprint(country_info)
if country_info.get('name', None):
self.__countries[country_info['name'].lower()] = country_info

# Update country name if it is one of alt spellings.
if self.__country_name in map(lambda an: an.lower(), country_info.get('altSpellings', [])):
self.__country_name = country_info['name'].lower()

def info(self):
"""Returns all available information for a specified country.
Expand All @@ -45,7 +47,6 @@ def info(self):

return _all


def provinces(self):
"""return provinces list
Expand All @@ -57,7 +58,6 @@ def provinces(self):

return _provinces


def iso(self, alpha=None):
"""Returns ISO codes for a specified country
Expand All @@ -77,7 +77,6 @@ def iso(self, alpha=None):

return _iso


def alt_spellings(self):
"""Returns alternate spellings for the name of a specified country
Expand All @@ -91,8 +90,7 @@ def alt_spellings(self):
return _alt_spellings
except KeyError:
return []



def area(self):
"""Returns area (km²) for a specified country
Expand All @@ -103,8 +101,7 @@ def area(self):
# pprint(_area)

return _area



def borders(self):
"""Returns bordering countries (ISO3) for a specified country
Expand All @@ -115,8 +112,7 @@ def borders(self):
# pprint(_borders)

return _borders



def calling_codes(self):
"""Returns international calling codes for a specified country
Expand All @@ -128,7 +124,6 @@ def calling_codes(self):

return _calling_codes


def capital(self):
"""Returns capital city for a specified country
Expand All @@ -140,7 +135,6 @@ def capital(self):

return _capital


def currencies(self):
"""Returns official currencies for a specified country
Expand All @@ -152,8 +146,6 @@ def currencies(self):

return _currencies



def demonym(self):
"""Returns the demonyms for a specified country
Expand All @@ -165,7 +157,6 @@ def demonym(self):

return _demonym


def flag(self):
"""Returns SVG link of the official flag for a specified country
Expand All @@ -177,8 +168,7 @@ def flag(self):
# pprint(_flag)

return _flag



def geo_json(self):
"""Returns geoJSON for a specified country
Expand All @@ -190,7 +180,6 @@ def geo_json(self):

return _geo_json


def languages(self):
"""Returns official languages for a specified country
Expand All @@ -201,8 +190,7 @@ def languages(self):
# pprint(_languages)

return _languages



def latlng(self):
"""Returns approx latitude and longitude for a specified country
Expand Down Expand Up @@ -232,7 +220,6 @@ def native_name(self):

return _native_name


def population(self):
"""Returns approximate population for a specified country
Expand All @@ -244,7 +231,6 @@ def population(self):

return _population


def region(self):
"""Returns general region for a specified country
Expand All @@ -255,8 +241,7 @@ def region(self):
# pprint(_region)

return _region



def subregion(self):
"""Returns a more specific region for a specified country
Expand All @@ -267,8 +252,7 @@ def subregion(self):
# pprint(_subregion)

return _subregion



def timezones(self):
"""Returns all timezones for a specified country
Expand All @@ -279,8 +263,7 @@ def timezones(self):
# pprint(_timezones)

return _timezones



def tld(self):
"""Returns official top level domains for a specified country
Expand All @@ -291,8 +274,7 @@ def tld(self):
# pprint(_tld)

return _tld



def translations(self):
"""Returns translations for a specified country name in popular languages
Expand All @@ -306,8 +288,7 @@ def translations(self):
return _translations
except KeyError:
return []



def wiki(self):
"""Returns link to wikipedia page for a specified country
Expand All @@ -320,7 +301,6 @@ def wiki(self):

return _wiki


def all(self):
"""return all of the countries information
Expand All @@ -332,7 +312,7 @@ def all(self):
return _all


if __name__=='__main__':
if __name__ == '__main__':
country = CountryInfo('Singapore')
pprint(country.all())

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

setup(
name='countryinfo',
version='0.1.0',
version='0.1.1',
python_requires='>3.0.0',
packages = find_packages(
include=['countryinfo'],
Expand Down
6 changes: 6 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
from countryinfo import CountryInfo


class Tests(unittest.TestCase):

all_countries = {}
Expand Down Expand Up @@ -55,5 +56,10 @@ def test_all_countries_have_translations(self):
except KeyError as err:
self.fail("Country '{0}' key error: {1}".format(name, err))

def test_select_country_from_alt_name(self):
country = CountryInfo('PK')
assert country.name() == 'pakistan'


if __name__ == '__main__':
unittest.main()

0 comments on commit 54f8d5b

Please sign in to comment.