Skip to content

Instantly share code, notes, and snippets.

@sturadnidge
Last active August 29, 2015 14:07
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 sturadnidge/b1acaa1a77c1d1803087 to your computer and use it in GitHub Desktop.
Save sturadnidge/b1acaa1a77c1d1803087 to your computer and use it in GitHub Desktop.
CSGO Lounge Match Watcher
'use strict';
// npm install cheerio moment optimist
var http = require('http'),
cheerio = require('cheerio'),
moment = require('moment'),
argv = require('optimist')
.usage('\nCheck csgolounge match stats every 30 secs.\n\nUsage: $0')
.demand(['d', 'i', 'm'])
.describe({'d':'the date of the match in ISO 8601 (e.g. 2014-02-13)', 'i':'an interval in seconds', 'm':'a valid match ID'})
.argv;
var matchId = argv.m,
checkInterval = (parseInt(argv.i) * 1000)
// main
console.log('timestamp,matchId,betCount,itemCount');
setInterval(function() { getMatch(matchId) }, checkInterval);
// functions
function getMatch(matchId) {
var html = '',
options = {
headers: {'user-agent':'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36'},
hostname: 'csgolounge.com',
path: '/match?m=' + matchId
};
var req = http.request(options, function (res) {
if (res.statusCode != '200') {
console.log('bad http response, check match id / site down');
return;
};
res.on('data', function (chunk) {
// all the page
html += chunk;
}).on('end', function () {
// now that we've finished reading the page
var $ = cheerio.load(html);
var betStats = $('div.full:nth-child(1)').html(),
teamA = $('section.box:nth-child(1) > div:nth-child(1) > a:nth-child(4) > span:nth-child(1) > b:nth-child(2)').html(),
teamB = $('section.box:nth-child(1) > div:nth-child(1) > a:nth-child(6) > span:nth-child(1) > b:nth-child(2)').html(),
matchStart = $('section.box:nth-child(1) > div:nth-child(1) > div:nth-child(3)').html();
betStats = betStats.trim().split(' ');
matchStart = matchStart.trim().split(' ')[0].replace(':','');
var matchId = argv.d + '-' + matchStart + '-' + teamA + '-' + teamB;
console.log(moment().unix() + ',' + matchId + ',' + betStats[0] + ',' + betStats[3])
});
});
req.on('error', function (err) {
console.log('error: ' + err.message);
});
req.write('\n');
req.end();
}
@Outzu
Copy link

Outzu commented Feb 20, 2015

how to install on wordpress widget?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment