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.
This example are make for python modules.
- 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)
- for example you can see our code are build with
async
in the function,
so if you are useing 'def' in yourmain.py
you need to addasyncio
at the top like this. - 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!