Skip to content

Instantly share code, notes, and snippets.

@rooreynolds
Created January 4, 2017 20:30
Show Gist options
  • Save rooreynolds/d25b6bf648bed62c73926e177741bdad to your computer and use it in GitHub Desktop.
Save rooreynolds/d25b6bf648bed62c73926e177741bdad to your computer and use it in GitHub Desktop.
What's on Radio 4 right now? via Node JS
const request = require('request')
,url = 'http://www.bbc.co.uk/radio4/programmes/schedules/fm.json'
request(url, (error, response, body)=> {
if (!error && response.statusCode === 200) {
const data = JSON.parse(body)
var schedule=data.schedule.day.broadcasts;
var myDate = new Date();
for (var i=0; i<schedule.length; i++) {
var startDate = Date.parse(schedule[i].start);
var endDate = Date.parse(schedule[i].end);
if (myDate > startDate && myDate < endDate) {
console.log(schedule[i].programme.display_titles.title);
console.log(schedule[i].programme.display_titles.subtitle);
console.log(schedule[i].programme.short_synopsis);
}
}
} else {
console.log("Got an error: ", error, ", status code: ", response.statusCode)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment