Last active
August 29, 2015 13:56
-
-
Save LeoMcA/8981510 to your computer and use it in GitHub Desktop.
Code behind @severnbot on Twitter
This file contains 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
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