Created
May 1, 2019 13:57
-
-
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
This file contains hidden or 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
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