Skip to content

Instantly share code, notes, and snippets.

@dzava
Created February 23, 2016 01:43
Show Gist options
  • Save dzava/3fc1afbee0eb77901739 to your computer and use it in GitHub Desktop.
Save dzava/3fc1afbee0eb77901739 to your computer and use it in GitHub Desktop.
Chunk OpenWeatherMap city list.
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