What's on the TV?

11

1

Challenge

Write a program which, using the XML data from the site here, display the name of the programme which is currently showing on BBC 1.

Information

All times are given at London time (GMT+1 at the time of posting and GMT+0 after the 30th October). Therefore, you should convert your local time to London time.

Each programme is given a start and end time. If the current time is after the start time and before the end time of a programme, that programme is currently showing. Your programme may handle overlaps in anyway you wish.

Your output must be the programme title, like so:

BBC News

However, if the programme has a subtitle (shown by the presence of the subtitle tag), the output should be like so:

Steptoe and Son: The Piano

Where Steptoe and Son is the title and The Piano is the subtitle. An example programme with a subtitle is as follows:

<programme>
    <subtitle>Newcastle</subtitle>
    <title>Flog It!</title>
    <end>1710</end>
    <start>1610</start>
    <desc>
      Antiques series. Paul Martin presents from the Discovery Museum in Newcastle. The items uncovered include a book of autographs with a local connection. Also in HD. [S]
    </desc>
</programme>

URL shorteners are disallowed but XML parsing libraries are allowed.

Winning

The shortest code in bytes wins.

Beta Decay

Posted 2016-08-20T18:58:22.973

Reputation: 21 478

Can you give a test case with a subtitle tag, because there (currently) is none in the linked xml file. – KarlKastor – 2016-08-20T19:04:48.003

@KarlKastor There you go – Beta Decay – 2016-08-20T19:07:57.867

Do we have to convert the local time to London time? – KarlKastor – 2016-08-20T19:34:51.520

@KarlKastor Yes, you do – Beta Decay – 2016-08-20T19:35:37.620

Must the code always grab the latest TV show, or can we grab the latest TV show as of now and use it? – Buffer Over Read – 2016-08-20T20:06:58.567

@ColdGolf What? No, it has to be the latest – Beta Decay – 2016-08-20T20:11:33.220

The link in your post has multiple show names. Which one do we use? – Buffer Over Read – 2016-08-20T20:12:52.907

@ColdGolf The question describes how you use the start and end times to find the latest show... – Beta Decay – 2016-08-20T20:14:44.523

I presume dates after midnight reflect programs that are on the day after the date specified by the date attribute in the root channel element? – H Walters – 2016-08-21T01:23:21.530

Wait, what if there is no program currently showing? That seems to be the case as of 0423 UTC+1 according to the link provided, as the very first item shown is a program that starts at 0600 UTC+1. – R. Kap – 2016-08-21T03:26:16.573

@R.Kap "Your programme may handle overlaps in anyway you wish." I imagine this includes dead air (so I would think any of: "None"; <previous program>; <next program>; something completely different - would be fine). EDIT: Nope - currently showing is "BBC News" - note the date says 20th but it's the 21st - look near the end of the file :) – Jonathan Allan – 2016-08-21T04:30:52.940

@HWalters Yes, they do – Beta Decay – 2016-08-21T09:06:12.633

2What exactly makes this "quick golf"? – Martin Ender – 2016-08-22T07:12:26.923

1@MartinEnder I suppose because I wrote it quickly :D – Beta Decay – 2016-08-22T08:24:01.553

IMO this would be better if xml libraries were not allowed. – Shaun Wild – 2016-08-22T11:50:51.143

@SeanBean That'd change the focus of the question though, and probably make it a dupe – Beta Decay – 2016-08-22T11:51:34.777

Answers

2

Bash + curl + XMLStarlet, 166 characters

d=`TZ=Europe/London date +%H%M`
curl -s bleb.org/tv/data/listings/0/bbc1.xml|xmlstarlet sel -t -m "//programme[start<=$d and end>$d]" -v title -m subtitle -o :\  -v .

Sample run:

bash-4.3$ date 
Mon Aug 22 14:17:07 EEST 2016

bash-4.3$ bash bbc.sh 
Bargain Hunt: Carmarthen

manatwork

Posted 2016-08-20T18:58:22.973

Reputation: 17 865

I'm not good at bash scripting , but is it possible to produce the website address via decompressing compressed version of address or something similar ? – None – 2016-08-22T14:27:33.443

Not really. Is too short for compression. Uncompressed has 36 bytes, compressed with gzip has 56 bytes. Other tools I tried produce even bigger result. – manatwork – 2016-08-22T14:36:33.760

5

Python, 440 428 426 398 395 Bytes

-31 Bytes thanks to @Loovjo

Throws an error when it found the date.

import re,pytz,urllib
from datetime import*
x=urllib.urlopen("http://www.bleb.org/tv/data/listings/0/bbc1.xml").read().split("</p")[:-1]
for m,n in enumerate(re.search("\d*</s",i).group()for i in x):
 if n>datetime.strftime(datetime.now(pytz.utc).astimezone(pytz.timezone('Europe/London')),"%H%M"):print re.search(">.*?</t",x[m-1]).group()[1:-3],": "+re.search("e>.*?</s",x[m-1]).group()[2:-3],_

Please don't hurt me for parsing xml with regex.

version using a xml parser, 398 Bytes

import re,pytz,urllib
import xml.etree.ElementTree as ET
from datetime import*
x=list(ET.parse(urllib.urlretrieve("http://www.bleb.org/tv/data/listings/0/bbc1.xml")[0]).getroot())
for m,n in enumerate(i.find("start").text for i in x):
 if n>datetime.strftime(datetime.now(pytz.utc).astimezone(pytz.timezone('Europe/London')),"%H%M"):print x[m-1].find("title").text,": "+x[0].find("subtitle").text,_

KarlKastor

Posted 2016-08-20T18:58:22.973

Reputation: 2 352

7It's okay, we've only got problems with the parsing of HTML with regex ;) – Beta Decay – 2016-08-20T20:00:29.927

1If I'm not mistaken, I think you can replace the break with something that causes an error (such as 1/0 (or maybe even _)). I'm pretty sure your submissions can exit with an error. – Loovjo – 2016-08-20T20:40:52.783

Are third party libs allowed? If yes, then you change urllib to use requests in your first example: x=requests.get(link).text.split("</p")[:-1]. That will save you 2 bytes. – Zizouz212 – 2016-08-20T21:33:25.600

@Zizouz212 Yes, requests is allowed

– Beta Decay – 2016-08-22T08:59:36.000