Created
December 23, 2012 13:50
-
-
Save stuartpb/4363507 to your computer and use it in GitHub Desktop.
A quick script I made to fix a mistake I'd made in setup for achewatr
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 mongodb = require("mongodb") | |
var env = require("jsdom").env | |
var url = require('url') | |
var queue = require("queue-async") | |
function onSuccess(cb){ | |
return function(err) { | |
if (err) { | |
console.error(err) | |
} else { | |
cb.apply(this,Array.prototype.slice.call(arguments,1)) | |
} | |
} | |
} | |
mongodb.MongoClient.connect(process.argv[2],onSuccess(function(db){ | |
var items = db.collection('items') | |
function updateItem(href,title,endCb){ | |
items.update({_id: href},{$set:{title: title}}, onSuccess(function(result){ | |
console.log(": "+href) | |
endCb(); | |
})) | |
} | |
var q=queue() | |
//Get www.achewood.com/list.php | |
console.log("Connecting to list page...") | |
env("http://www.achewood.com/list.php", onSuccess(function(window){ | |
console.log("Connected to list page") | |
var document = window.document | |
var dds = document.getElementsByTagName('dd') | |
//For each page: | |
for (var i = 0; i < dds.length; ++i) { | |
var anchor = dds[i].getElementsByTagName('a')[0]; | |
q.defer(updateItem,anchor.href,anchor.textContent); | |
} | |
q.awaitAll(function(){db.close();}) | |
})) | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment