Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@MichaelPaulukonis
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MichaelPaulukonis/3d371a8294bd556cd253 to your computer and use it in GitHub Desktop.
Save MichaelPaulukonis/3d371a8294bd556cd253 to your computer and use it in GitHub Desktop.
Discourse notifications parser (from local file)

In http://bbs.boingboing.net there is a little game that where we communicate only by changing the text of the thread title/subject. While edits are archived in vanilla Discourse, certain agitators had this data removed from public access.

Now, the originator of the thread still receives notifications, but some hoops must be jumped-through.

I grabbed the list by going to my notifications, opening page-inspector, selecting the element that held the notifications, copied the innerHTML and save that to a file.

This file is then processed via node.js - see eat.js

Caveats - title-edits by the thread originator are not visible, since the originator receives no notifications regarding own edits.

There is another view-edit feature on the thread-page itself, but AFAICT it requires clicking through each edit.

Discourse also has an API that I haven't looked at.

// eat the file
var fs = require('fs');
var filename = 'notifications.txt';
var writeitout = function(notes) {
var text = [];
var fs = require('fs');
notes.forEach(function(note) {
text.push('<strong>' + note.title + '</strong> - _' + note.name + '_ @ ' + note.date);
});
var fn = 'notifies.' + (Math.random() * 0x1000000000).toString(36) + '.txt';
fs.writeFile(fn, text.join('\n'));
console.log('\n\nWritten to ' + fn);
};
fs.readFile(filename, 'utf8', function(err, data) {
if (err) {
return console.log(err);
}
var lines = data.trim().split('\n');
var notes = [];
var capturing = false;
var targLine = '';
// here are two sample target lines
// <li class="ember-view read" id="ember2933"><a href="/t/i-suppose-youre-all-wondering-why-i-asked-you-here-today-well-youre-all-being-remixed-doesnt-that-sound-wonderful/55981"><i title="edited" class="fa fa-pencil"></i><p><span>monkeyoh</span> I suppose you're all wondering why I asked you here today. Well, you're all being remixed. Doesn't that sound wonderful?</p></a></li>
// <span class="relative-date date" title="April 23, 2015 4:40pm" data-time="1429821607501" data-format="medium-with-ago">30 mins ago</span>
var isTarg = /55981.*edited/;
var nameCapture = /<span>(.*)<\/span>/;
var titleCapture = /<\/span> (.*)<\/p>/;
var isDate = /relative-date/;
var dateCapture = /title="(.*?)" data-time/;
lines.forEach(function(line) {
line = line.trim().replace('\r', '');
if (capturing && isDate.test(line) ) {
capturing = false;
dateline = line;
var date = dateCapture.exec(line)[1];
// console.log(date[1]);
var name = nameCapture.exec(targLine)[1];
// console.log(name[1]);
var title = titleCapture.exec(targLine)[1];
// console.log(title[1]);
notes.push({title: title, name: name, date: date});
targLine = '';
return;
}
if (isTarg.test(line)) {
capturing = true;
targLine = line;
return;
}
});
writeitout(notes);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment