Skip to content

Instantly share code, notes, and snippets.

@prwhite prwhite/gist:5846493
Created Jun 23, 2013

Embed
What would you like to do?
Q&D node.js script to pull out any Google Reader items tagged with a public label, e.g., "starred".
#!/usr/bin/env node --harmony
"use strict";
var req = require ( "request" );
var fs = require ( "fs" );
# replace these... could be command line args but that would have taken like 15 seconds more.
var userid = "06674516782868565233";
var label = "starred";
var incr = 1000;
var root = "http://www.google.com/reader/public/atom/user/" + userid + "/label/" + label;
var cur = incr;
function dl ( start, cb )
{
let qstr = "?n=1000";
if ( start != "" )
{
let match = start.match ( /<gr:continuation>(.*?)<\/gr:continuation>/ );
if ( match )
{
qstr += "&c=" + match[ 1 ];
console.log ( "found continuation " + match[ 1 ] );
}
else
{
cb ( { error: "No continuation token found" }, 0, null );
}
}
let next = root + qstr;
console.log ( "requesting " + next );
req ( next, cb );
}
function rec ( error, response, body )
{
if ( ! error )
{
let fname = label + cur + ".xml";
console.log ( "writing file " + fname );
fs.writeFileSync ( fname, body, "utf8" );
cur += incr;
dl ( body, rec );
}
else
{
console.log ( "error:", error, response );
process.exit ( 0 );
}
}
dl ( "", rec );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.