plaincities is a library of places in many languages.
Project description
plaincities is a library of places in many languages. It is based on geonames database.
Installation
pip install plaincities
Usage
Load options:
from plaincities import Globe
globe = Globe(load_all=True)
globe = Globe(continents_to_load=['AF', 'AS'])
globe = Globe(countries_to_load=['IN', 'MX'])
globe = Globe()
india = globe['IN']
india.load_cities()
Hierarchy & Administrative Divisions:
from plaincities import Globe
globe = Globe(countries_to_load=['MY'])
malaysia = globe['MY']
medium_cities = list(malaysia.cities.filter(lambda x: x.population > 100000 and x.population < 1000000 and x.district is not None))['/'.join(
[c.state.name, c.district.name, c.name, c.admin_division.name])
for c in medium_cities][0:10]
['Johor/Daerah Batu Pahat/Batu Pahat/Place',
'Johor/Daerah Johor Baharu/Kampung Pasir Gudang Baru/Place',
'Johor/Daerah Johor Baharu/Skudai/Section',
'Johor/Daerah Johor Baharu/Johor Bahru/City',
'Johor/Daerah Keluang/Kluang/Place',
'Johor/Daerah Muar/Muar town/Place',
'Selangor/Petaling/Shah Alam/Place',
'Selangor/Klang/Klang/Place',
'Sabah/Kota Kinabalu/Kota Kinabalu/City',
'Sabah/Lahad Datu/Lahad Datu/Place']
Coordinates:
globe = Globe(countries_to_load=['IN'])
india = globe['IN']
kochi = india.cities.find('Kochi')
(kochi.latitude, kochi.longitude)
(9.93988, 76.26022)
globe = Globe(countries_to_load=['IN'])
india = globe['IN']
varanasi = india.cities.find('Varanasi')
new_delhi = india.cities.find('New Delhi')
f'~{round(varanasi.distance_to(new_delhi) / 1000)} km.'
'~682 km.'
Timezones:
globe = Globe(countries_to_load=['MX'])
mexico = globe['MX']
merida = mexico.cities.find('Merida')
merida.timezone.key
'America/Merida'
Switching languages:
from plaincities import Globe
globe = Globe(language='zh', countries_to_load=['CN'])
china = globe['CN']
beijing = china.cities.find('北京')
(china.name, beijing.name, beijing.ascii_name)
('中国', '北京', 'Beijing')
Suggestions:
from plaincities import Globe
globe = Globe(countries_to_load=['GR'])
greece = countries['GR']
list(greece.cities.suggest('Tesaloniki', threshold=0.7))
['Heraklion', 'Thessaloniki']
Generating language files
Default installation supports English, Turkish, French, Spanish, Chinese, Russian and Arabic. If you need other languages, you need to download the following files from the geonames website and put them into the same folder:
countryInfo.txt, alternateNamesv2.zip, admin1CodesASCII.txt, admin2Codes.txt, cities(N).zip
from plaincities import generator
Generator('data', 'new_values').generate_values('cities15000.txt', languages=['ko'], default_language='ko')
from plaincities import Globe
globe = Globe(countries_to_load=['TH'], path='new_values')
thailand = countries['TH']
thailand.name
'태국'
Contact:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file plaincities-0.3.1.tar.gz.
File metadata
- Download URL: plaincities-0.3.1.tar.gz
- Upload date:
- Size: 18.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.4 Linux/6.2.0-37-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b6b9405e68af8b8dc1a7b21b0e23ee6a57179b11993c14e613142cc9db3e002
|
|
| MD5 |
df4d1bf6703e3610ff9dd50c12dde11c
|
|
| BLAKE2b-256 |
7fcd67d66dfdecd3454e40e82c1eaf3557b05138b0393776242be01078881494
|
File details
Details for the file plaincities-0.3.1-py3-none-any.whl.
File metadata
- Download URL: plaincities-0.3.1-py3-none-any.whl
- Upload date:
- Size: 19.3 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.4 Linux/6.2.0-37-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1da7e8a5bbbb14133d1f5168896ed6dd1f895000efd44b2ce20c7b974cb4f31
|
|
| MD5 |
283bd5844a31e74fa4307ab51a713f08
|
|
| BLAKE2b-256 |
a930405954fdbc72d78f91ab49263290e1966dab85702d8a77e60c9a1d6d8c22
|