Created
June 23, 2013 20:46
-
-
Save prwhite/5846493 to your computer and use it in GitHub Desktop.
Q&D node.js script to pull out any Google Reader items tagged with a public label, e.g., "starred".
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
#!/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