Created
February 23, 2016 01:43
-
-
Save dzava/3fc1afbee0eb77901739 to your computer and use it in GitHub Desktop.
Chunk OpenWeatherMap city list.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs') | |
var rawData = JSON.parse(fs.readFileSync('city.list.json', 'utf8')) | |
var formatedData = {} | |
rawData.forEach(function(city){ | |
var country = city.country | |
if (!(country in formatedData)){ | |
formatedData[country] = {} | |
formatedData[country].cities = {} | |
} | |
formatedData[country].cities[city._id] = city.name | |
}); | |
Object.keys(formatedData).forEach(function(countryCode){ | |
var country = formatedData[countryCode] | |
fs.writeFileSync("/tmp/data/" + countryCode + ".json", JSON.stringify(country.cities)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment