a quick program to download tv listings
Erik Lechak
prochak at netzero.net
Thu Sep 11 02:37:47 EDT 2003
Hello all,
Is there anyone out there that has written anything in python to
download tv listings (no XML)?
All the tv listing stuff that I can find is way too complex for my
taste (includes XML overkill or is not in python). I wrote the test
program below and it works. I am just curious if anyone has a more
robust python implementation before I take the time to add all the
bells and whistles.
Chron is just a class like datetime, but I wrote it to accept just
about every english way of expressing time. The important thing is to
put the epoch time in the URL.
If anyone is interested in Chron, I can post it or send it to them.
Hope you enjoy the code,
Erik Lechak
import urllib
import re
from pygra.Chron import Chron
class Show:
'''
Just a structure to hold program information
'''
def __init__(self):
name=""
channel=""
station=""
start=""
end=""
def getGrid(timestring):
shows=[]
t=Chron(timestring)
f = urllib.urlopen('http://tv.yahoo.com/grid?lineup=us_DMA560&genres=&dur=&starttime='+str(int(t.epoch))+'&.intl=us')
data = f.read()
data=[d.strip('\n') for d in data]
data="".join(data)
data=data.split("</A>")
for d in data:
progs = re.findall('<A HRef="\/tvpdb\?d=tvp&id=(.*)',d)
for s in progs:
m= re.search('(\d*)&cf.*channels=us_([^&]*).*&chname=([^\+]*)\+(\d+)&progutn=(\d*)&.*>(.*)',s)
show=Show()
show.name=m.group(6)
show.start=m.group(5)
show.channel=int(m.group(4))
show.station=m.group(3)
shows.append(show)
return shows
shows =getGrid('now')
for s in [s for s in shows if s.channel==17]:
print s.name
More information about the Python-list
mailing list