Do you want a database which contains most of cities in the world as well as the countries? This app will save 2 collections to your mongodb:
cities
(23328 in total)countries
(252 in total)
Even better, the
- Language agnostic because it's not a lib. Consume the result database using any language you like.
- Source data from GeoNames.org is under active updates. And this app will let you update in few seconds.
- No other 3rd party libs dependencies but official
pymongo
python main.py
to generate the database from source datapython update.py
to update the source data from GeoNames- Remove any fields you don't need in
settings.py
- Support
currency symbol
which not included in the GeoNames (like$
forUSD
) - Easy to add support for other database. See
FAQ
part. - Could filter countries which only speak certain languages. (see
setting.py
) - Could add "duplicate" data to prevent more queries in MongoDB (see
settings.py
)
- Python 3
- Python 2 should be fine, but haven't tried.
-
git clone https://github.com/Mr-Binary/world-cities-mongodb.git
-
pip install pymongo
-
Open
settings.py
, set up your database settings. -
python main.py
-
Enjoy :)
- To update the source data in
data
folder:python update.py
[data]
: [Folder] Raw data from GeoNames[models]
: [Folder] database model for city and country[utils]
: [Folder] Helper functionsettings.py
: Settingsmain.py
: Main file to generate the databaseupdate.py
: Update the sourcedata
from GeoNames
-
The data is from GeoNames.
-
The
cities
contains cities which population greater than 15000. -
How to update the data
python update.py
-
The URL of source data from GeoNames:
- Every execution will drop the previous collection and generate new one.
- It's very easy, you just need to refactor the
save_cities()
andsave_countries()
inmongodb.py
, then it will be called at run time with the list of data to insert.