13
\$\begingroup\$

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.

\$\endgroup\$
16
  • \$\begingroup\$ Can you give a test case with a subtitle tag, because there (currently) is none in the linked xml file. \$\endgroup\$
    – KarlKastor
    Aug 20, 2016 at 19:04
  • \$\begingroup\$ @KarlKastor There you go \$\endgroup\$
    – Beta Decay
    Aug 20, 2016 at 19:07
  • \$\begingroup\$ Do we have to convert the local time to London time? \$\endgroup\$
    – KarlKastor
    Aug 20, 2016 at 19:34
  • 2
    \$\begingroup\$ What exactly makes this "quick golf"? \$\endgroup\$ Aug 22, 2016 at 7:12
  • 1
    \$\begingroup\$ @MartinEnder I suppose because I wrote it quickly :D \$\endgroup\$
    – Beta Decay
    Aug 22, 2016 at 8:24

2 Answers 2

5
\$\begingroup\$

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,_
\$\endgroup\$
4
  • 7
    \$\begingroup\$ It's okay, we've only got problems with the parsing of HTML with regex ;) \$\endgroup\$
    – Beta Decay
    Aug 20, 2016 at 20:00
  • 1
    \$\begingroup\$ If 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. \$\endgroup\$
    – xenia
    Aug 20, 2016 at 20:40
  • \$\begingroup\$ 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. \$\endgroup\$
    – Zizouz212
    Aug 20, 2016 at 21:33
  • \$\begingroup\$ @Zizouz212 Yes, requests is allowed \$\endgroup\$
    – Beta Decay
    Aug 22, 2016 at 8:59
2
\$\begingroup\$

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
\$\endgroup\$
2
  • \$\begingroup\$ 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 ? \$\endgroup\$
    – user55673
    Aug 22, 2016 at 14:27
  • \$\begingroup\$ 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. \$\endgroup\$
    – manatwork
    Aug 22, 2016 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.