Skip to content

constantinedev/Python-Country-List

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

Python-Country-List

script for return country list by json format
This is not for installation for the code.
This code are write with python and modules with pytz and pycountry,
check the usage for how to return the formate for you code.

Usage

This example are make for python modules.

  1. Save the ,py file for example name: CountryList.py and exapmle you code as 'run.py'
import asyncio
from .CountryList import CountryList

async def main():
  ctyList = await CountryList()
  print(ctyList)

def main():
  ctyList = asyncio.run(CountryList())
  print(ctyList)
  1. for example you can see our code are build with async in the function,
    so if you are useing 'def' in your main.py you need to add asyncio at the top like this.
  2. In the CountryList.py, you can config the return data as you need.
_data = {
  "code": country.alpha_2,
  "name": country.name,
  "offset": offset,
  "timezone": timezone,
}

This is the part of pycountry return datas.
it had already get timezone[Country/City], offset[+04:00], name[Country Name], code[CA,GB,FR...etc]
as you need to change the return id also config it in CountryList.py

It use the pytz for for faster short the offset formate, you can menu install by pip
python3 -m pip install -U pytz pycountry
Any cusntom API need with the modules, you can edit with you free!

About

script for return country list by json format

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages