Skip to content

Instantly share code, notes, and snippets.

@xavi-
Created September 19, 2012 21:56
Show Gist options
  • Save xavi-/3752564 to your computer and use it in GitHub Desktop.
Save xavi-/3752564 to your computer and use it in GitHub Desktop.
var fs = require("fs");
var TwoStep = require("two-step");
var jsdom = require("jsdom");
TwoStep(
function() { fs.readFile("./cities.json", this.val()); },
function(err, cities) {
if(err) { throw err; }
cities = JSON.parse(cities);
var info = this.valArray();
for(var city in cities) {
getCityInfo(city, cities[city], info.val());
}
},
function(err, info) {
if(err) { throw err; }
fs.writeFile("./timezone-info.json", JSON.stringify(info, null, "\t"), this.val());
},
function(err) { if(err) { throw err; } }
);
function getCityInfo(shortName, url, callback) {
TwoStep(
function() { jsdom.env(url, ['http://code.jquery.com/jquery-1.7.1.min.js'], this.val()); },
function(err, window) {
if(err) { return callback(error); }
var $ = window.$;
return callback(
null,
{
"short-name": shortName,
url: url,
name: $(".biggest").text(),
abbreviation: $("#cta").text(),
latitude: $(".rpad:contains(Latitude) tr:eq(0) td:not(:first-child)").text(),
longitude: $(".rpad:contains(Latitude) tr:eq(1) td:not(:first-child)").text(),
offset: $(".lpad tr:contains(offset) td:not(:first-child)").text() ||
$(".lpad tr:contains(Standard time zone) td:not(:first-child)").text()
}
);
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment