How I Made a Country-Info Project Using Python

How I Made a Country-Info Project Using Python

Subscribe to my newsletter and never miss my upcoming articles

Listen to this article

Hey guys, I would be sharing out on how I made a python project that provides you with information of any country in the world, including a map and a QR-Code that stores more information of the country.

  • You can check how the code runs here🎥
  • You can also access the source code here🖥

Okay, let's get started🚀

  • Firstly, I needed to import some libraries/ modules to make this workout, using pip install. So, we would be installing three of them. So go ahead to run this commands on your terminal.
    pip install countryinfo
    pip install qrcode[pil]
    pip install folium
    

1.) You get to start writing your codes but you need to import them into your codes/ .py file

import qrcode
import folium
from countryinfo import CountryInfo

2.) I printed out a message and asked for an input(country) from the user and assigned the user into name variable. Then, I created a variable, called the CountryInfo function and passed the user input(country).

print('Welcome, You can get information about any country here!')
user = input('\nEnter the name of a country:\n')
name = user
country = CountryInfo(name)

3.) You can access the information you want this this piece of code.

data = country.info()
for x,y in data.items():
    print(f'{x} --> {y}')

This piece of code above would give you lots of information about any country, then you can pick out specific functions you want by the keyword the code is going to provide while rendering the information. I went ahead to edit mine to ame it look better. The keywords I meant are the functions I called after country in the codes below country_name = country.alt_spellings(). The keyword/ function here is the .alt_spellings(), this is specifically for country alternative names.

country_name = country.alt_spellings()
print('\nName:')
for name in country_name:
    print(name, end= ', ')

country_capital =country.capital()
print(f'\n\nCapital:\n{country_capital}')

country_currency = country.currencies()
print('\nCurrency:')
for currency in country_currency:
    print(currency, end= ', ')

country_lang = country.languages()
print('\n\nLanguages:')
for languages in country_lang:
    print(languages, end =', ')

country_timezone = country.timezones()
print('\n\nTime-Zone:')
for timezones in country_timezone:
    print(timezones, end = ', ')

country_area = country.area()
print(f'\n\nCountry Area:\n{country_area}')

country_borders = country.borders()
print('\nBorders:')
for border in country_borders:
    print(border, end=', ')

calling_codes= country.calling_codes()
print('\n\nCall Code:')
for call_code in calling_codes:
    print(call_code)

country_region = country.region()
print(f'\nRegion:\n{country_region}')

sub_region = country.subregion()
print(f'\nSub-Region:\n{sub_region}')

country_population = country.population()
print(f'\nPopulation:\n{country_population}')

country_states = country.provinces()
print('\nStates/Provinces:')
for states in country_states:
    print(states, end=', ')

4.) It is time for making a map in an .html format. I used the keyword/ function.capital_latlng() to get the latitude and longitude of a country. I then used the foluim function and pass the longitude and latitude using the country_map variable . I printed out a message and used a string format {user} to get the name of the country. Then, I lastly saved the file.

country_map = country.capital_latlng()
map = folium.Map(location = (country_map))
print(f'\n\nCheck your directory for the map of  {user}, named: (mylocation.html)')
map.save("mylocation.html")

5.) Lastly, I created a QR-Code storing more of the country's information. The function.wiki() gives a Wikipedia page containing information about the country. I passed it in the data variable, then created a QR-Code and passed the data into it. If you would love to know how to create a QR-Code, click here

about_country = country.wiki()

data = about_country
qr = qrcode.QRCode( version = 1, box_size = 15, border = 5)
qr.add_data(data)
qr.make(fit = True)
img = qr.make_image(fill_color = 'black', back_color = 'white')
print(f'\nCheck your directory for the qr code containing the information of {user}, named: (about_country.png)')
img.save('C:/Users/chryz/Desktop/about_country.png')

I hope you all found this useful. Please kindly comment below for feedback and you can link up with me on Twitter @chryz_codez and on this platform for more engagement🤝!⠀

 
Share this