Skip to content

Instantly share code, notes, and snippets.

@hom3chuk
Created May 1, 2019 13:57
Show Gist options
  • Save hom3chuk/05240c8aae6c6fa03bbe6f4f01497aa9 to your computer and use it in GitHub Desktop.
Save hom3chuk/05240c8aae6c6fa03bbe6f4f01497aa9 to your computer and use it in GitHub Desktop.
small js script to check MTGA sub for new codes giveaway with Mac OS X notifications. Run with node
const {exec} = require('child_process')
var request = require('request');
var options = {
host: 'www.reddit.com',
path: '/r/MagicArena/new/',
followAllRedirects: true
};
var expired = [ // expired code posts titles
'<h2 class="s15fpu6f-0 jcIrny">Anyone have an extra prerelease code for arena?</h2>',
'<h2 class="s15fpu6f-0 jcIrny">Twitch prime code.</h2>',
]
const check = function() {
request({
followAllRedirects: true,
url: 'https://www.reddit.com/r/MagicArena/new/'
}, function (err, resp, body) {
var found = body.match(/(<h2[^<]*?code[^<]*?<\/h2>)/gism)
let f = false
if( found ) {
found.forEach(function(f){
if (-1 === expired.indexOf(f) ) {
console.log(f)
console.log("get it at https://www.reddit.com/r/MagicArena/new/")
exec('osascript -e \'display notification "!!!" with title "New reddit MTGA code!"\'')
} else {
console.log('only old codes :(')
}
})
} else {
console.log(resp.statusCode + ' no codes for u ' + new Date())
}
setTimeout(check, 15000)
}).on('error', function (e) {
exec('osascript -e \'display notification "Err" with title "Reddit Err!"\'')
console.log("Got error: " + e.message);
setTimeout(check, 15000)
});
}
check()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment