Code Monkey home page Code Monkey logo

plaincities's Introduction

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:

[email protected]

plaincities's People

Contributors

ufukk avatar

Watchers

 avatar  avatar

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.