Created
September 22, 2009 08:06
-
-
Save neilbradley/190917 to your computer and use it in GitHub Desktop.
Programme data in JSON format to feed the Glow Timetable
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
{ | |
"blocklist": [ | |
{ | |
"service": "channel7", | |
"service_title": "Channel 7", | |
"start": "2009-03-09T14:42:02", | |
"end": "2009-03-09T15:42:02", | |
"emp_title": "Being Human: Series 1: Episode 5" | |
}, | |
{ | |
"service": "channel7", | |
"service_title": "Channel 7", | |
"start": "2009-03-09T16:30:26", | |
"end": "2009-03-09T17:30:26", | |
"emp_title": "Being Human: Series 1: Episode 5" | |
}, | |
{ | |
"service": "channel7", | |
"service_title": "Channel 7", | |
"start": "2009-03-09T18:10:46", | |
"end": "2009-03-09T18:15:46", | |
"emp_title": "West 10 LDN SDA0061" | |
}, | |
{ | |
"service": "channel7", | |
"service_title": "Channel 7", | |
"start": "2009-03-09T19:00:00", | |
"end": "2009-03-09T19:45:00", | |
"emp_title": "Doctor Who: Series 3: The Family of Blood" | |
}, | |
{ | |
"service": "channel7", | |
"service_title": "Channel 7", | |
"start": "2009-03-09T19:45:00", | |
"end": "2009-03-09T20:00:00", | |
"emp_title": "Doctor Who Confidential: Series 3: Bad Blood" | |
}, | |
{ | |
"service": "channel7", | |
"service_title": "Channel 7", | |
"start": "2009-03-09T20:00:00", | |
"end": "2009-03-09T20:30:00", | |
"emp_title": "The Real Hustle: Series 5: High Stakes: Episode 6" | |
}, | |
{ | |
"service": "channel7", | |
"service_title": "Channel 7", | |
"start": "2009-03-09T20:30:00", | |
"end": "2009-03-09T21:00:00", | |
"emp_title": "Snog Marry Avoid?: Series 2: Episode 4" | |
}, | |
{ | |
"service": "channel7", | |
"service_title": "Channel 7", | |
"start": "2009-03-09T21:00:00", | |
"end": "2009-03-09T21:30:00", | |
"emp_title": "Gavin and Stacey: Series 2: Episode 5" | |
}, | |
{ | |
"service": "channel7", | |
"service_title": "Channel 7", | |
"start": "2009-03-09T21:30:00", | |
"end": "2009-03-09T22:00:00", | |
"emp_title": "Grownups: Series 3: Balls" | |
}, | |
{ | |
"service": "channel7", | |
"service_title": "Channel 7", | |
"start": "2009-03-09T22:00:00", | |
"end": "2009-03-09T22:30:00", | |
"emp_title": "EastEnders: 09/03/2009" | |
}, | |
{ | |
"service": "channel7", | |
"service_title": "Channel 7", | |
"start": "2009-03-09T22:30:00", | |
"end": "2009-03-09T23:10:00", | |
"emp_title": "Heroes: Series 3: Cold Wars" | |
}, | |
{ | |
"service": "channel7", | |
"service_title": "Channel 7", | |
"start": "2009-03-09T23:10:00", | |
"end": "2009-03-09T23:35:00", | |
"emp_title": "Family Guy: Series 4: Peter's Got Woods" | |
}, | |
{ | |
"service": "channel7", | |
"service_title": "Channel 7", | |
"start": "2009-03-09T23:35:00", | |
"end": "2009-03-09T23:55:00", | |
"emp_title": "Family Guy: Series 4: Jungle Love" | |
}, | |
{ | |
"service": "channel7", | |
"service_title": "Channel 7", | |
"start": "2009-03-09T23:55:00", | |
"end": "2009-03-10T00:25:00", | |
"emp_title": "Gavin and Stacey: Series 2: Episode 5" | |
}, | |
{ | |
"service": "channel7", | |
"service_title": "Channel 7", | |
"start": "2009-03-10T00:25:00", | |
"end": "2009-03-10T00:55:00", | |
"emp_title": "Grownups: Series 3: Balls" | |
}, | |
{ | |
"service": "channel7", | |
"service_title": "Channel 7", | |
"start": "2009-03-10T00:55:00", | |
"end": "2009-03-10T01:25:00", | |
"emp_title": "Snog Marry Avoid?: Series 2: Episode 4" | |
}, | |
{ | |
"service": "channel7", | |
"service_title": "Channel 7", | |
"start": "2009-03-10T01:25:00", | |
"end": "2009-03-10T01:50:00", | |
"emp_title": "Two Pints of Lager and a Packet of Crisps: Series 8: Comic Relief Special" | |
}, | |
{ | |
"service": "channel7", | |
"service_title": "Channel 7", | |
"start": "2009-03-10T01:50:00", | |
"end": "2009-03-10T02:50:00", | |
"emp_title": "Two Pints: Fags, Lads and Kebabs" | |
}, | |
{ | |
"service": "channel7", | |
"service_title": "Channel 7", | |
"start": "2009-03-10T02:50:00", | |
"end": "2009-03-10T03:50:00", | |
"emp_title": "Dangerous Love: A Comic Relief Special" | |
}, | |
{ | |
"service": "channel7", | |
"service_title": "Channel 7", | |
"start": "2009-03-10T03:50:00", | |
"end": "2009-03-10T05:30:00", | |
"emp_title": "Freaky Eaters: Series 3: Addicted to Beans and Chips" | |
}, | |
{ | |
"service": "channel7", | |
"service_title": "Channel 7", | |
"start": "2009-04-09T14:42:02", | |
"end": "2009-04-09T15:42:02", | |
"emp_title": "Being Human: Series 1: Episode 5" | |
}, | |
{ | |
"service": "channel7", | |
"service_title": "Channel 7", | |
"start": "2009-04-09T16:30:26", | |
"end": "2009-04-09T17:30:26", | |
"emp_title": "Being Human: Series 1: Episode 5" | |
}, | |
{ | |
"service": "channel7", | |
"service_title": "Channel 7", | |
"start": "2009-04-09T18:10:46", | |
"end": "2009-04-09T18:15:46", | |
"emp_title": "West 10 LDN SDA0061" | |
}, | |
{ | |
"service": "channel7", | |
"service_title": "Channel 7", | |
"start": "2009-04-09T19:00:00", | |
"end": "2009-04-09T19:45:00", | |
"emp_title": "Doctor Who: Series 3: The Family of Blood" | |
}, | |
{ | |
"service": "channel7", | |
"service_title": "Channel 7", | |
"start": "2009-04-09T19:45:00", | |
"end": "2009-04-09T20:00:00", | |
"emp_title": "Doctor Who Confidential: Series 3: Bad Blood" | |
}, | |
{ | |
%0 |
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB" lang="en-GB"> | |
<head profile="http://dublincore.org/documents/dcq-html/"> | |
<title> | |
Loading Timetable Data From A Remote Source | |
</title> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<meta name="description" content="Glow version 1.6 API Documentation" /> | |
<meta name="keywords" content="" /> | |
<script type="text/javascript" src="http://node1.bbcimg.co.uk/glow/gloader.0.1.2.js"> | |
gloader.use("glow", {map: "http://node1.bbcimg.co.uk/glow/glow/map.1.6.1.js"}); | |
</script> | |
<style type="text/css"> | |
#myTimetable { | |
height: 660px; | |
} | |
#myTimetable h2 { | |
padding: 0 5px; | |
margin: 0; | |
height: 40px; | |
color: #fff; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="myTimetable"></div> | |
<script type="text/javascript"> | |
(function() { | |
function scaleMe(data) { | |
var start = data.start, | |
hours = Math.floor(start.valueOf() / 3600000) % 24, | |
ampm = ["am", "pm"][Math.floor(hours / 12)], | |
hh = ((hours - 24) % 12) + 12; | |
return hh + ampm; | |
} | |
function makeDate(sDate) { | |
var adjusted = sDate.replace(/^([0-9]{4})-([0-9]{2})-([0-9]{2}).([0-9]{2}):([0-9]{2}):([0-9]{2})$/, "$1/$2/$3 $4:$5:$6"); | |
return new Date(adjusted); | |
} | |
function process(netResponse) { | |
var list = netResponse.json().blocklist, | |
i = list.length, | |
services = {}, | |
programmes = null, | |
latest = new Date(0), | |
earliest = new Date("2099/12/31 23:59:59"), | |
thisStart = null, | |
thisEnd = null, | |
thisService = null; | |
// grab required tracks and transform items | |
while (i--) { | |
thisService = list[i].service; | |
services[thisService] = services[thisService] || {title: list[i].service_title, programmes: []}; | |
programmes = services[thisService].programmes; | |
thisStart = makeDate(list[i].start); | |
thisEnd = makeDate(list[i].end); | |
// deduce required Timetable end points | |
if(thisStart.valueOf() < earliest.valueOf()) { | |
earliest = thisStart; | |
} | |
if(thisEnd.valueOf() > latest.valueOf()) { | |
latest = thisEnd; | |
} | |
programmes[programmes.length] = [ | |
list[i].emp_title, | |
thisStart, | |
thisEnd | |
]; | |
} | |
// deduce required Timetable view points | |
var viewStart = new Date(earliest.valueOf() + 3 * 60 * 60 * 1000), | |
viewEnd = new Date(earliest.valueOf() + 6 * 60 * 60 * 1000), | |
tracks = [] | |
trackSize = 150; | |
// transform grabbed tracks | |
for(var id in services) { | |
tracks[tracks.length] = [services[id].title, trackSize, {items: services[id].programmes}]; | |
} | |
// disable all tracks but the first 4. tracks[j][2] is the options object | |
// this is so we have something that fits the page | |
/*for(var j = 4, len = tracks.length; j < len; j++) { | |
tracks[j][2].disabled = true; | |
}*/ | |
// console.log({ | |
// tracks: tracks, | |
// earliest: earliest, | |
// latest: latest, | |
// viewStart: viewStart, | |
// viewEnd: viewEnd | |
// }); | |
return { | |
tracks: tracks, | |
earliest: earliest, | |
latest: latest, | |
viewStart: viewStart, | |
viewEnd: viewEnd | |
}; | |
} | |
gloader.load(["glow", "1", "glow.net", "glow.widgets.Timetable"],{ | |
async: true, | |
onLoad: function(glow) { | |
glow.ready(function(){ | |
glow.net.get("channel7.json", {onLoad: function (response) { | |
var processed = process(response), | |
myTimetable = new glow.widgets.Timetable("#myTimetable", | |
processed.earliest, processed.latest, | |
processed.viewStart, processed.viewEnd, | |
{ | |
size: 600, | |
tracks: processed.tracks | |
} | |
).setBanding("hour") | |
.addScale("hour", "left", 83, {template: scaleMe}) | |
.addScrollbar("hour", "right", 50, {template: scaleMe}) | |
.setTrackHeaderTemplate("<" + "h2>{title}</" + "h2>") | |
.draw(); | |
}}); | |
}); | |
} | |
}); | |
})(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment