Skip to content

Instantly share code, notes, and snippets.

@bryanmr
Last active February 1, 2019 18:57
Show Gist options
  • Save bryanmr/c8299c3f0b0a60eb4d80626b6ce1e7bd to your computer and use it in GitHub Desktop.
Save bryanmr/c8299c3f0b0a60eb4d80626b6ce1e7bd to your computer and use it in GitHub Desktop.
A simple NodeJS script to parse out the permalink and title from Reddit search
// https://www.reddit.com/r/linux_gaming/search.json?q=author%3Abryanindurham&restrict_sr=1
// https://www.reddit.com/wiki/search
// Get Command Line Arguments
filename=process.argv[2];
console.log("Checking: " + filename);
// Read the file from command line
fs = require('fs')
fs.readFile(filename, 'utf8',
function (err,data)
{
if (err)
{
return console.log(err);
}
// children is an array in JSON
// We are interested in the title and permalink
myJSON=JSON.parse(data);
IntermediateParsing=myJSON.data;
for (i=0; i<IntermediateParsing.children.length; i++)
{
outNum=i+1;
console.log("Output number: "+outNum+" of "+IntermediateParsing.children.length);
console.log(myJSON.data.children[i].data.title);
console.log("https://reddit.com"+myJSON.data.children[i].data.permalink);
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment