Giter Club home page Giter Club logo

countryinfo's Introduction

Country Info

A python module for returning data about countries, ISO info and states/provinces within them.

Table of Contents

APIs

Acknowledgement

Install

pip install countryinfo

OR, git clone

git clone https://github.com/porimol/countryinfo.git

cd countryinfo
python setup.py install

API Usage

To access one of the country properties available, you'll need to use one of the API methods listed below and pass a country in either way.

.info()

Returns all available information for a specified country.

# coding=utf-8
from countryinfo import CountryInfo


country = CountryInfo('Singapore')
country.info()
# returns object,
{
    'ISO': {
        'alpha2': 'SG',
        'alpha3': 'SGP'
    },
    'altSpellings': [
        'SG',
        'Singapura',
        'Republik Singapura',
        '新加坡共和国'
    ],
    'area': 710,
    'borders': [],
    'callingCodes': ['65'],
    'capital': 'Singapore',
    'capital_latlng': [
        1.357107,
        103.819499
    ],
    'currencies': ['SGD'],
    'demonym': 'Singaporean',
    'flag': '',
    'geoJSON': {},
    'languages': [
        'en',
        'ms',
        'ta',
        'zh'
    ],
    'latlng': [
        1.36666666,
        103.8
    ],
    'name': 'Singapore',
    'nativeName': 'Singapore',
    'population': 5469700,
    'provinces': ['Singapore'],
    'region': 'Asia',
    'subregion': 'South-Eastern Asia',
    'timezones': ['UTC+08:00'],
    'tld': ['.sg'],
    'translations': {
        'de': 'Singapur',
        'es': 'Singapur',
        'fr': 'Singapour',
        'it': 'Singapore',
        'ja': 'シンガポール'
    },
    'wiki': 'http://en.wikipedia.org/wiki/singapore',
    'google': 'https://www.google.com/search?q=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()

Return provinces list

# coding=utf-8
from countryinfo import CountryInfo


country = CountryInfo('Singapore')
country.provinces()
# returns object,
['Singapore']

.alt_spellings()

Returns alternate spellings for the name of a specified country

# coding=utf-8
from countryinfo import CountryInfo


country = CountryInfo('Singapore')
country.alt_spellings()
# returns list of strings, alternate names
# ['SG', 'Singapura', 'Republik Singapura', '新加坡共和国']

.area()

Returns area (km²) for a specified country

# coding=utf-8
from countryinfo import CountryInfo


country = CountryInfo('Singapore')
country.area()
# returns number of square kilometer area
710

.borders()

Returns bordering countries (ISO3) for a specified country

# coding=utf-8
from countryinfo import CountryInfo


country = CountryInfo('Singapore')
country.borders()
# returns array of strings, ISO3 codes of countries that border the given country
[]

.calling_codes()

Returns international calling codes for a specified country

# coding=utf-8
from countryinfo import CountryInfo


country = CountryInfo('Singapore')
country.calling_codes()
# returns array of calling code strings
['65']

.capital()

Returns capital city for a specified country

# coding=utf-8
from countryinfo import CountryInfo


country = CountryInfo('Singapore')
country.capital()
# returns string
'Singapore'

.capital_latlng()

Returns capital city latitude and longitude for a specified country

# coding=utf-8
from countryinfo import CountryInfo


country = CountryInfo('Singapore')
country.capital_latlng()
# returns array, approx latitude and longitude for country capital
[1.357107, 103.819499]

.currencies()

Returns official currencies for a specified country

# coding=utf-8
from countryinfo import CountryInfo


country = CountryInfo('Singapore')
country.currencies()
# returns array of strings, currencies
# ['SGD']

.demonym()

Returns the demonyms for a specified country

# coding=utf-8
from countryinfo import CountryInfo


country = CountryInfo('Singapore')
country.demonym()
# returns string, name of residents
'Singaporean'

.geo_json()

Returns geoJSON for a specified country

# coding=utf-8
from countryinfo import CountryInfo


country = CountryInfo('Bangladesh')
country.geo_json()
# returns object of GeoJSON data

{
    'features': [
        {
            'geometry': {
                'coordinates': [[[92.672721, 22.041239],
                                             [92.652257, 21.324048],
                                             [92.303234, 21.475485],
                                             [92.368554, 20.670883],
                                             [92.082886, 21.192195],
                                             [92.025215, 21.70157],
                                             [91.834891, 22.182936],
                                             [91.417087, 22.765019],
                                             [90.496006, 22.805017],
                                             [90.586957, 22.392794],
                                             [90.272971, 21.836368],
                                             [89.847467, 22.039146],
                                             [89.70205, 21.857116],
                                             [89.418863, 21.966179],
                                             [89.031961, 22.055708],
                                             [88.876312, 22.879146],
                                             [88.52977, 23.631142],
                                             [88.69994, 24.233715],
                                             [88.084422, 24.501657],
                                             [88.306373, 24.866079],
                                             [88.931554, 25.238692],
                                             [88.209789, 25.768066],
                                             [88.563049, 26.446526],
                                             [89.355094, 26.014407],
                                             [89.832481, 25.965082],
                                             [89.920693, 25.26975],
                                             [90.872211, 25.132601],
                                             [91.799596, 25.147432],
                                             [92.376202, 24.976693],
                                             [91.915093, 24.130414],
                                             [91.46773, 24.072639],
                                             [91.158963, 23.503527],
                                             [91.706475, 22.985264],
                                             [91.869928, 23.624346],
                                             [92.146035, 23.627499],
                                             [92.672721, 22.041239]]],
                            'type': 'Polygon'
                },
               'id': 'BGD',
               'properties': {'name': 'Bangladesh'},
               'type': 'Feature'}],
    'type': 'FeatureCollection'
}

.iso()

Returns ISO codes for a specified country

# coding=utf-8
from countryinfo import CountryInfo


country = CountryInfo('Singapore')
country.iso()
# returns object of ISO codes
{'alpha2': 'SG', 'alpha3': 'SGP'}

country.iso(2)
# returns object of ISO codes
'SG'


country.iso(3)
# returns object of ISO codes
'SGP'

.languages()

Returns official languages for a specified country

# coding=utf-8
from countryinfo import CountryInfo


country = CountryInfo('Singapore')
country.languages()
# returns array of language codes
['en', 'ms', 'ta', 'zh']

.latlng()

Returns approx latitude and longitude for a specified country

# coding=utf-8
from countryinfo import CountryInfo


country = CountryInfo('Singapore')
country.latlng()
# returns array, approx latitude and longitude for country
[1.36666666, 103.8]

.native_name()

Returns the name of the country in its native tongue

# coding=utf-8
from countryinfo import CountryInfo


country = CountryInfo('Singapore')
country.native_name()
# returns string, name of country in native language
'Singapore'

.population()

Returns approximate population for a specified country

# coding=utf-8
from countryinfo import CountryInfo


country = CountryInfo('Singapore')
country.population()
# returns number, approx population
5469700

.region()

Returns general region for a specified country

# coding=utf-8
from countryinfo import CountryInfo


country = CountryInfo('Singapore')
country.region()
# returns string
'Asia'

.subregion()

Returns a more specific region for a specified country

# coding=utf-8
from countryinfo import CountryInfo


country = CountryInfo('Singapore')
country.subregion()
# returns string
'South-Eastern Asia'

.timezones()

Returns all timezones for a specified country

# coding=utf-8
from countryinfo import CountryInfo


country = CountryInfo('Singapore')
country.timezones()
# returns array of timezones
['UTC+08:00']

.tld()

Returns official top level domains for a specified country

# coding=utf-8
from countryinfo import CountryInfo


country = CountryInfo('Singapore')
country.tld()
# returns array of top level domains specific to the country
['.sg']

.translations()

Returns translations for a specified country name in popular languages

# coding=utf-8
from countryinfo import CountryInfo


country = CountryInfo('Singapore')
country.translations()
# returns object of translations of country name in major languages
{
    'de': 'Singapur',
    'es': 'Singapur',
    'fr': 'Singapour',
    'it': 'Singapore',
    'ja': 'シンガポール'
}

.wiki()

Returns link to wikipedia page for a specified country

# coding=utf-8
from countryinfo import CountryInfo


country = CountryInfo('Singapore')
country.wiki()
# returns string URL of wikipedia article on country
'http://en.wikipedia.org/wiki/singapore'

.google()

Returns link to google page for a specified country

# coding=utf-8
from countryinfo import CountryInfo


country = CountryInfo('Singapore')
country.google()
# returns string URL of google page on country
'https://www.google.com/search?q=Singapore'

.all()

Returns array of objects containing all available data for all countries. This will be super big. Not recommended.

# coding=utf-8
from countryinfo import CountryInfo


country = CountryInfo()
country.all()
# returns array of objects,
{
    'zimbabwe': {'ISO': {'alpha2': 'ZW', 'alpha3': 'ZWE'},
              'altSpellings': ['ZW', 'Republic of Zimbabwe'],
              'area': 390757,
              'borders': ['BWA', 'MOZ', 'ZAF', 'ZMB'],
              'callingCodes': ['263'],
              'capital': 'Harare',
              'capital_latlng': [-17.831773, 31.045686],
              'currencies': ['USD'],
              'demonym': 'Zimbabwean',
              'flag': '',
              'geoJSON': {'features': [{'geometry': {'coordinates': [[[31.191409,
                                                                       -22.25151],
                                                                      [30.659865,
                                                                       -22.151567],
                                                                      [30.322883,
                                                                       -22.271612],
                                                                      [29.839037,
                                                                       -22.102216],
                                                                      [29.432188,
                                                                       -22.091313],
                                                                      [28.794656,
                                                                       -21.639454],
                                                                      [28.02137,
                                                                       -21.485975],
                                                                      [27.727228,
                                                                       -20.851802],
                                                                      [27.724747,
                                                                       -20.499059],
                                                                      [27.296505,
                                                                       -20.39152],
                                                                      [26.164791,
                                                                       -19.293086],
                                                                      [25.850391,
                                                                       -18.714413],
                                                                      [25.649163,
                                                                       -18.536026],
                                                                      [25.264226,
                                                                       -17.73654],
                                                                      [26.381935,
                                                                       -17.846042],
                                                                      [26.706773,
                                                                       -17.961229],
                                                                      [27.044427,
                                                                       -17.938026],
                                                                      [27.598243,
                                                                       -17.290831],
                                                                      [28.467906,
                                                                       -16.4684],
                                                                      [28.825869,
                                                                       -16.389749],
                                                                      [28.947463,
                                                                       -16.043051],
                                                                      [29.516834,
                                                                       -15.644678],
                                                                      [30.274256,
                                                                       -15.507787],
                                                                      [30.338955,
                                                                       -15.880839],
                                                                      [31.173064,
                                                                       -15.860944],
                                                                      [31.636498,
                                                                       -16.07199],
                                                                      [31.852041,
                                                                       -16.319417],
                                                                      [32.328239,
                                                                       -16.392074],
                                                                      [32.847639,
                                                                       -16.713398],
                                                                      [32.849861,
                                                                       -17.979057],
                                                                      [32.654886,
                                                                       -18.67209],
                                                                      [32.611994,
                                                                       -19.419383],
                                                                      [32.772708,
                                                                       -19.715592],
                                                                      [32.659743,
                                                                       -20.30429],
                                                                      [32.508693,
                                                                       -20.395292],
                                                                      [32.244988,
                                                                       -21.116489],
                                                                      [31.191409,
                                                                       -22.25151]]],
                                                     'type': 'Polygon'},
                                        'id': 'ZWE',
                                        'properties': {'name': 'Zimbabwe'},
                                        'type': 'Feature'}],
                          'type': 'FeatureCollection'},
              'languages': ['en', 'sn', 'nd'],
              'latlng': [-20, 30],
              'name': 'Zimbabwe',
              'nativeName': 'Zimbabwe',
              'population': 13061239,
              'provinces': ['Bulawayo',
                            'Harare',
                            'ManicalandMashonaland Central',
                            'Mashonaland East',
                            'Mashonaland'],
              'region': 'Africa',
              'subregion': 'Eastern Africa',
              'timezones': ['UTC+02:00'],
              'tld': ['.zw'],
              'translations': {'de': 'Simbabwe',
                               'es': 'Zimbabue',
                               'fr': 'Zimbabwe',
                               'it': 'Zimbabwe',
                               'ja': 'ジンバブエ'},
              'wiki': 'http://en.wikipedia.org/wiki/zimbabwe',
              'google': 'https://www.google.com/search?q=Zimbabwe'}
}

Special Thanks

Special thanks to johan for his work on johan/world.geo.json, who made the geojson portion of this build possible.

Inspired By

Repo: countryjs

Maintainer: Oz Haven

Contributing

See the list of contributors who participated in this project.

How to become a contributor

If you want to contribute to countryinfo and make it better, your help is very welcome. You can make constructive, helpful bug reports, feature requests and the noblest of all contributions. If like to contribute in a good way, then follow the following guidelines.

How to make a clean pull request

  • Create a personal fork on Github.
  • Clone the fork on your local machine.(Your remote repo on Github is called origin.)
  • Add the original repository as a remote called upstream.
  • If you created your fork a while ago be sure to pull upstream changes into your local repository.
  • Create a new branch to work on! Branch from dev.
  • Implement/fix your feature, comment your code.
  • Follow countryinfo's code style, including indentation(4 spaces).
  • Write or adapt tests as needed.
  • Add or change the documentation as needed.
  • Push your branch to your fork on Github, the remote origin.
  • From your fork open a pull request to the dev branch.
  • Once the pull request is approved and merged, please pull the changes from upstream to your local repo and delete your extra branch(es).

Disclaimer

This is being maintained in the contributor's free time, and as such, may contain minor errors in regards to some countries. Most of the information included in this library is what is listed on Wikipedia. If there is an error, please let me know and I will do my best to correct it.

License

Copyright (c) 2018, Porimol Chandro [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

countryinfo's People

Contributors

20geomine avatar arslanhashmi avatar atifiu avatar dilettagoglia avatar fayasnoushad avatar hersche avatar jannikj avatar kaspersorensen avatar pcorpet avatar porimol avatar praneetshekhar avatar propegasus avatar sgonsal avatar sohansolo avatar squeaky-pl avatar voidus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

countryinfo's Issues

Documentation enhancement

Hi,
Great package!
Good you mention which data sources you are using in the readme?
Also, perhaps for which year the data is valid (e.g. important for population, but also for changing borders, ...).
Thanks for the package!
Best
kst

Add alpha3 code to alt spelling

Currently countries entered as alpha3 codes result in KeyErrors since the alt spelling includes only alpha2 codes. Appending alpha3 codes from ISO would solve this.

Longitude of Serbia is wrong

The value of 'latlng' for Serbia is [44.1305021, 16.4284181], which is a point in Bosnia, close to the border to Croatia. From Google, the correct values should be 44.0165° N, 21.0059° E.

Not all countries are available in CountryInfo.all()

Hello

I can't found all countries in CountryInfo.
Here is the list of countries code I haven't found: AD, AQ, MM, BQ, CW, BV, AX, TC, VG, VI, UM, ME, PS

Is that possible to add this (some or all) this countries ? Even if there is not much information about them ...

Thank you in advance

Encoding problem

'm trying to use countryinfo with django 2.2 to get the countries informations :
when I tried to get this :

country = 'Morocco' 
information = CountryInfo(country)

I get this error:
'charmap' codec can't decode byte 0x81 in position 49: character maps to <undefined>

Czechia/Czech Republic

Hello,
Would it be possible to update the name for Czechia (formerly Czech Republic) as this is causing issues with other databases.

Thanks!

Wales and Scotland json are not complet

Great Job for this library, It 's a country library complete, I use it with Django Rest Framework.

Two Element I modify to on library comportement.

  • The first is ordering the country by name because the first was monaco.
  • the second is Wales and scotland json file are not filled like others

but it a good lib. I hope you will have more stars

Summertime in CH

Hello, nice lib!

I would like to show the diffrent times of the diffrent countrys in a chat..

while try out, i found that switzerland have timezone utc+1, which is kind of correct in general.. however, we have summertime, so this is not true at the moment (rather utc+2).

https://greenwichmeantime.com/time-zone/europe/switzerland/time/

not shure how to solve that in structure.. show the currently active or add it to the array? i let that up to you.. however, a method with a datetime-object of current datetime there would be very cool as well!

best regards

vinz

Could you clarify an intended way of validation?

I work with few databases, and I can't control the exact country name used.
Hence, I need to validate DB names vs names in your library.
For example: 'Polska' instead of 'Poland'

What I came up with is:

def isCountryNameValid(name: str) -> bool:
    rv = True
    try:
        c = CountryInfo(name)
        data = c.native_name()
    except KeyError:
        rv = False
    return rv

If you have something better in mind (and I couldn't figure that out) -- could you add to API documentation?
Otherwise, maybe you'd like to add it, or share your view and I could try implement if myself :)

Issue with the scotland.json file

First of all, thank you for making such a useful and user friendly library available for free! This has already saved me hours of work and has made my code a lot less hack-y in its implementation of population databases. With that said, I noticed that the scotland.json file seems to be much more out-of-date when compared to other json files in the data folder (including those that were not updated in the latest (May 2020) commit). It is not only in a seemingly different format, but does not contain most of the data that I assume it should (for example, population). This has made it incompatible with some of this library's functions. This isn't a big deal, and I was able to fix it by rewriting the file in my install and including the information that I needed (primarily population data), I just wanted to let you know in-case you encounter a similar issue. I would be happy to share my rewritten file once I make sure it is compatible with functions that I have not had to use it with. Please let me know if I have made some mistake or am misunderstanding the issue and thanks again for this otherwise great library!

Current Scotland File:

{
    "name": "Scotland",
    "flag": "",
    "geoJSON": {},
    "ISO": {
        "alpha2": "",
        "alpha3": ""
    },
    "provinces": ["Aberdeen City", "Aberdeenshire", "Angus", "Argyll and Bute", "City of Edinburgh", "Clackmannanshire", "Dumfries and Galloway", "Dundee City", "East Ayrshire", "East Dunbartonshire", "East Lothian", "East Renfrewshire", "Eilean Siar (Western Isles)", "Falkirk", "Fife", "Glasgow City", "Highland", "Inverclyde", "Midlothian", "Moray", "North Ayrshire", "North Lanarkshire", "Orkney Islands", "Perth and Kinross", "Renfrewshire", "Shetland Islands", "South Ayrshire", "South Lanarkshire", "Stirling", "The Scottish Borders", "West Dunbartonshire", "West Lothian"],
    "tld": [],
    "wiki": "http://en.wikipedia.org/wiki/scotland"
}

Compatible File:

{"name":"Saudi Arabia","altSpellings":["SA","Kingdom of Saudi Arabia","Al-Mamlakah al-‘Arabiyyah as-Su‘ūdiyyah"],"area":2149690,"borders":["IRQ","JOR","KWT","OMN","QAT","ARE","YEM"],"callingCodes":["966"],"capital":"Riyadh","capital_latlng":[24.631969,46.715065],"currencies":["SAR"],"demonym":"Saudi Arabian","flag":"","geoJSON":{"type":"FeatureCollection","features":[{"type":"Feature","id":"SAU","properties":{"name":"Saudi Arabia"},"geometry":{"type":"Polygon","coordinates":[[[42.779332,16.347891],[42.649573,16.774635],[42.347989,17.075806],[42.270888,17.474722],[41.754382,17.833046],[41.221391,18.6716],[40.939341,19.486485],[40.247652,20.174635],[39.801685,20.338862],[39.139399,21.291905],[39.023696,21.986875],[39.066329,22.579656],[38.492772,23.688451],[38.02386,24.078686],[37.483635,24.285495],[37.154818,24.858483],[37.209491,25.084542],[36.931627,25.602959],[36.639604,25.826228],[36.249137,26.570136],[35.640182,27.37652],[35.130187,28.063352],[34.632336,28.058546],[34.787779,28.607427],[34.83222,28.957483],[34.956037,29.356555],[36.068941,29.197495],[36.501214,29.505254],[36.740528,29.865283],[37.503582,30.003776],[37.66812,30.338665],[37.998849,30.5085],[37.002166,31.508413],[39.004886,32.010217],[39.195468,32.161009],[40.399994,31.889992],[41.889981,31.190009],[44.709499,29.178891],[46.568713,29.099025],[47.459822,29.002519],[47.708851,28.526063],[48.416094,28.552004],[48.807595,27.689628],[49.299554,27.461218],[49.470914,27.109999],[50.152422,26.689663],[50.212935,26.277027],[50.113303,25.943972],[50.239859,25.60805],[50.527387,25.327808],[50.660557,24.999896],[50.810108,24.754743],[51.112415,24.556331],[51.389608,24.627386],[51.579519,24.245497],[51.617708,24.014219],[52.000733,23.001154],[55.006803,22.496948],[55.208341,22.70833],[55.666659,22.000001],[54.999982,19.999994],[52.00001,19.000003],[49.116672,18.616668],[48.183344,18.166669],[47.466695,17.116682],[47.000005,16.949999],[46.749994,17.283338],[46.366659,17.233315],[45.399999,17.333335],[45.216651,17.433329],[44.062613,17.410359],[43.791519,17.319977],[43.380794,17.579987],[43.115798,17.08844],[43.218375,16.66689],[42.779332,16.347891]]]}}]},"ISO":{"alpha2":"SA","alpha3":"SAU"},"languages":["ar"],"latlng":[25,45],"nativeName":"العربية السعودية","population":30770375,"provinces":["'Asir","Al Bahah","Al Hudud ash Shamaliyah","Al Jawf","Al Madinah","Al Qasim","Ar Riyad","Ash Sharqiyah (Eastern Province)","Ha'il","Jizan","Makkah","Najran","Tabuk"],"region":"Asia","subregion":"Western Asia","timezones":["UTC+03:00"],"tld":[".sa"],"translations":{"de":"Saudi-Arabien","es":"Arabia Saudí","fr":"Arabie Saoudite","ja":"サウジアラビア","it":"Arabia Saudita"},"wiki":"http://en.wikipedia.org/wiki/saudi_arabia"}

Not giving a country name returns Eritrea

> CountryInfo().name()
'eritrea'

Question is, what is good behaviour here? I'd argue that since a CountryInfo object represents information about a specific country, a constructor argument should be mandatory.

Probably easier to do #41 first, since right now, accessing .all() requires constructing an object.

Please add provinces of Scotland to UK file.

I realise it is a politically charged issue, but since Scotland is still legally a part of the United Kingdom, one would expect to find Scotland's provinces in the list of UK's provinces.

Alternatively, please add Scotland as a province in the UK file.

Jerusalem is not the captial of Israel

Jerusalem is illegally occupied by Israel, and isn't even technically part of Israel. It is an individual territory granted special status according to the UN.

Cache outside of the CountryInfo object

Currently, all files are loaded every time a CountryInfo object is created. That's inefficient and should be changed.

Easiest would probably be to move the data loading part to a cached global function

Add capital coordinates?

Hi, thanks for the nice package! Would you be interested in an "enhancement" PR which adds the capital's coordinates (lat/lng), e.g. via a method .capital_latlng() or whatever you suggest as a suitable name? If you think this is helpful, I'm happy to create a PR.

.all() improvements

Semantically, .all() should not be a method of the CountryInfo object, since that one represents the information for a specific country.

Instead, it should probably be a global function. While we're at it, I'd also say it should return a list of CountryInfo objects. If a user wants to access a specific one, they can create a CountryInfo object, so fast access isn't a big issue, and it would hide the json structure from library users.

Implementation-wise, this would be easier after #40

Feature request - Demonym in multiple languages

Hello :)

Congrats on this beautiful library that you created! I have a feature request, would it be possible to add demonyms in multiple languages?

Thank you :)

//edit//

i suppose this would require setting the 'demonym' class to 'dict' instead of 'str' in the countryinfo.py file and editing the json files,

Wikipedia has a rather complete list with i.e. french demonyms: https://en.wiktionary.org/wiki/Appendix:French_demonyms

I'd try to prepare an edit if someone can explain to me how to programmatically make the necessary changes to the hundreds of json files...

Serbia, using alternate spelling 'RS' will fail to create a valid CountryInfo object

I try to get the info() output from Serbia while I use iso alpha2 "RS" for the country name.

CountryInfo('RS').info()

The code fails with an key error for 'rs' While 'RS' is not in the altSpellings list.

File "..\countryinfo.py", line 133, in capital _capital = self.__countries[self.__country_name]['capital'] KeyError: 'rs'

Running this code for other countries using alpha2 will work.
CountryInfo('DE').info()

I'm not sure if the the constructor of CountryInfo should support the iso alpha2 name as well?

I tried than to switch to full country name and encountered a problem with country name Czechia. Your help is much appriceated.

BR Lama

Example does not work

This example does not work:

country = CountryInfo('SG') print(country.info())

KeyError: 'sg'

Missing countries

Hey,

thanks for your work. I found that serbia is not existing in your project yet and therefore not found. Would be nice if this is included.

https://en.wikipedia.org/wiki/Serbia

If you would prefer a PR with a such json, let me know and i will take the time.

Macau missing key 'capital_latlng'

I run into a key error while try to access capital_latlng from Macau.

CountryInfo('Macau').info()['capital_latlng']

Despite that there no capital city exist, a nan or empty string as return value, would be preferred..

Missing country: Andorra

It currently appears that the data for Andorra is missing. For a complete global dataset it would be much appreciated if this was present.

Thank you!

Way to use .borders() info?

I want to get the population of the bordering countries to my input, the .borders() method returns, I believe, the alpha3 ISO code for the bordering countries, but the library does not accept alpha3 ISO codes as input. Is there an easy way to convert between the ISO code and the country name? Or to output .borders() info in an input-able format? In the meantime, I am going to add the ISO codes to the altSpellings list which will make them input-able, but I would love an official, cleaner fix!

Countryinfo package charmap error

Hi!

I tried to use countryinfo package to match a country to it's continent but am still getting a charmap error message.

from countryinfo import CountryInfo
country = CountryInfo('France')
country.region()

File "...\AppData\Local\Programs\Python\Python37\lib\encodings\cp1257.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0xa1 in position 47: character maps to

PyCharm console:

sys.getdefaultencoding()
'utf-8'

So, why does it complain about CP1257 encoding?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.