[wiki] wiki-lenny -> wiki
darcs-hash:20090427173001-bd074-51c7f6aea2843640e34adc0921b478f40ea98609.gz
This commit is contained in:
parent
5f26116790
commit
cd037bbbe9
31 changed files with 0 additions and 0 deletions
91
wiki/macro/TV.py
Normal file
91
wiki/macro/TV.py
Normal file
|
@ -0,0 +1,91 @@
|
|||
Dependencies = ["Time"]
|
||||
|
||||
|
||||
|
||||
SAP_FILE_URL = "http://tv/sap.txt"
|
||||
BASE_IMAGE_URL = "http://tv/images/"
|
||||
IMAGE_SUFFIX = ".jpg"
|
||||
SMALL_IMAGE_SUFFIX = "_petites.jpg"
|
||||
|
||||
|
||||
def image_url_for_channel(channel_name, channel_ip, small=0 ):
|
||||
if small:
|
||||
return BASE_IMAGE_URL + str(channel_ip) + IMAGE_SUFFIX
|
||||
else:
|
||||
return BASE_IMAGE_URL + str(channel_ip) + SMALL_IMAGE_SUFFIX
|
||||
|
||||
def get_channel_list():
|
||||
import urllib
|
||||
# Getsap file from web sever.
|
||||
f = urllib.urlopen(SAP_FILE_URL)
|
||||
# Read it.
|
||||
s = f.read()
|
||||
f.close()
|
||||
|
||||
s = s.split("\n")
|
||||
|
||||
channel_list = []
|
||||
for a_line in s:
|
||||
try:
|
||||
ch_name, ch_ip = a_line.split(":")
|
||||
url = "udp://@%s:1234" % ch_ip
|
||||
d = {
|
||||
"name": ch_name,
|
||||
"url": url,
|
||||
"image_url": image_url_for_channel( ch_name, ch_ip ),
|
||||
"small_image_url": image_url_for_channel( ch_name, ch_ip, small=1 ),
|
||||
}
|
||||
channel_list.append(d)
|
||||
except:
|
||||
pass
|
||||
return channel_list
|
||||
|
||||
|
||||
def execute(macro, args):
|
||||
opt = {"col":4,"cat":False,"ch":False, "width":"10em"}
|
||||
# parse args
|
||||
if args:
|
||||
try:
|
||||
for name, value in [(x.split("=")[0].strip(), x.split("=")[1].strip()) for x in args.split(",")]:
|
||||
opt[name] = value
|
||||
except:
|
||||
pass
|
||||
|
||||
IMAGES_PER_LINE = int(opt["col"])
|
||||
CATHEGORY = opt["cat"]
|
||||
CHANNEL = opt["ch"]
|
||||
IMAGE_WIDTH = opt["width"]
|
||||
# display all channel
|
||||
ch_list = get_channel_list()
|
||||
text = macro.formatter.table(1,{})
|
||||
i = 0
|
||||
for a_channel in ch_list:
|
||||
if CATHEGORY:
|
||||
if not a_channel["name"].startswith(CATHEGORY):
|
||||
continue
|
||||
if CHANNEL:
|
||||
if a_channel["name"].find(CHANNEL)<0:
|
||||
continue
|
||||
if i == 0:
|
||||
text+= macro.formatter.table_row(1)
|
||||
text+= macro.formatter.table_cell(1, {'style':'text-align:center;'})
|
||||
text+= macro.formatter.strong( 1 )
|
||||
text+= macro.formatter.text( a_channel["name"] )
|
||||
text+= macro.formatter.strong( 0 )
|
||||
text+= macro.formatter.linebreak( 0 )
|
||||
#text+= macro.formatter.url(1, href=a_channel["url"], style="text-decoration:none;")
|
||||
text+= macro.formatter.url(1, url=a_channel["url"], style="text-decoration:none;")
|
||||
text+= macro.formatter.image( src=a_channel["image_url"], alt="No image", style="width:%s;" % IMAGE_WIDTH )
|
||||
text+= macro.formatter.linebreak( 0 )
|
||||
text+= macro.formatter.text( "Regarder maintenant" )
|
||||
text+= macro.formatter.url(0)
|
||||
text+= macro.formatter.table_cell(0)
|
||||
if i == IMAGES_PER_LINE - 1:
|
||||
text+= macro.formatter.table_row(0)
|
||||
i = (i + 1) % IMAGES_PER_LINE
|
||||
while i != 0 and i < IMAGES_PER_LINE:
|
||||
text+= macro.formatter.table_cell(1)
|
||||
text+= macro.formatter.table_cell(0)
|
||||
i += 1
|
||||
text+= macro.formatter.table(0)
|
||||
return text
|
Loading…
Add table
Add a link
Reference in a new issue