# plugs/films.py
#
#

""" laat zien welke films er draaien op tv """

__copyright__ = 'this file is in the public domain'

from gozerbot.generic import geturl
from gozerbot.commands import cmnds
from gozerbot.generic import hourmin
from gozerbot.rsslist import rsslist
from gozerbot.plughelp import plughelp
import time

plughelp.add('films', 'show what films are running on tv today (dutch)')

def handle_films(bot, ievent):
    """ show films on tv today (dutch) """
    txt = geturl('http://www.filmtotaal.nl/trackers/xml/filmsoptv.xml')
    data = rsslist(txt)
    if not data:
        ievent.reply("can't match xml data")
        return
    result = ""
    ttime = time.time()
    for i in data:
        try:
            if ttime < float(i['eindtijd']):
                result += "%s [%s] %s-%s %s  .. " % (i['titel'], \
i['imdb_cijfer'], hourmin(float(i['starttijd'])), \
hourmin(float(i['eindtijd'])), i['zender'])
        except:
            pass
    if result:
        ievent.reply("http://www.filmtotaal.nl/module.php?section=fotv ==> " \
+ result[:-4])
    else:
        ievent.reply("can't match xml data")

cmnds.add('films', handle_films, ['USER', 'WEB'])
