Skip to content

Instantly share code, notes, and snippets.

@LeoMcA
Last active August 29, 2015 13:56
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 LeoMcA/8981510 to your computer and use it in GitHub Desktop.
Save LeoMcA/8981510 to your computer and use it in GitHub Desktop.
Code behind @severnbot on Twitter
var request = require('request');
var cheerio = require('cheerio');
var twit = require('twit');
var t = new twit({
consumer_key: ''
, consumer_secret: ''
, access_token: ''
, access_token_secret: ''
});
stations = [
'2039', // Diglis
'2092' // Barbourne
]
function scrape(){
stations.forEach(function(station){
var url = 'http://www.environment-agency.gov.uk/homeandleisure/floods/riverlevels/120744.aspx?stationId=' + station;
request(url, function(err, res, body){
$ = cheerio.load(body);
var unparsedLevel = $('#station-detail-left .plain_text p').eq(0).html();
var unparsedTime = $('#station-detail-left .plain_text p').eq(1).html();
console.log(unparsedLevel, unparsedTime);
t.post('statuses/update', { status: unparsedLevel + ' ' + unparsedTime + ' #worcesterfloods' }, function(err, reply) {
console.log(err, reply);
});
});
});
}
setInterval(scrape, 5 * 60 * 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment