https://github.com/albert-gao/world-cities-mongodb
A free world cities database
https://github.com/albert-gao/world-cities-mongodb
cities cities-mongodb countries database geolocation mongodb python
Last synced: 3 months ago
JSON representation
A free world cities database
- Host: GitHub
- URL: https://github.com/albert-gao/world-cities-mongodb
- Owner: Albert-Gao
- Created: 2017-09-30T10:51:38.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2020-03-27T20:44:20.000Z (over 5 years ago)
- Last Synced: 2025-04-15T02:26:04.668Z (6 months ago)
- Topics: cities, cities-mongodb, countries, database, geolocation, mongodb, python
- Language: Python
- Size: 2.49 MB
- Stars: 30
- Watchers: 2
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# world-cities-mongodb
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:
1. `cities`(**23328** in total)
1. `countries`(**252** in total)Even better, the
## Why use it
- Language agnostic because it's not a lib. Consume the result database using any language you like.
- Source data from [GeoNames.org](http://www.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 data
- `python 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 `$` for `USD`)
- 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 version
- Python 3
- Python 2 should be fine, but haven't tried.## How to use
1. `git clone https://github.com/Mr-Binary/world-cities-mongodb.git`
1. `pip install pymongo`
1. Open `settings.py`, set up your database settings.
1. `python main.py`
1. Enjoy :)
- To update the source data in `data` folder: **`python update.py`**
## Folder Structure
- `[data]`: [Folder] Raw data from GeoNames
- `[models]`: [Folder] database model for city and country
- `[utils]`: [Folder] Helper function
- `settings.py`: Settings
- `main.py`: Main file to generate the database
- `update.py`: Update the source `data` from GeoNames## About the data
- The data is from [GeoNames](http://www.geonames.org/).
- The `cities` contains cities which population greater than 15000.
- How to update the data
- **`python update.py`**- The URL of source data from GeoNames:
- [cities15000.zip](http://download.geonames.org/export/dump/cities15000.zip)
- [countryInfo.txt](http://download.geonames.org/export/dump/countryInfo.txt)## FAQ
### What will happen if I run the app twice
- Every execution will drop the previous collection and generate new one.
### How about support other database
- It's very easy, you just need to refactor the `save_cities()` and `save_countries()` in `mongodb.py`, then it will be called at run time with the list of data to insert.