# Figure out which other elements of an episode page are available.
import os, string
# Check for the existence of a file.
def exists(filename):
try:
os.stat(filename)
return 1
except:
return 0
#
# Input: integer episode number
# Output: (guide, background, synopsis, credits, prev, next)
#
def getneighbors(which, page = 'guide'):
whichstr = '%03d' % which
prev = '%03d' % (which - 1)
next = '%03d' % (which + 1)
hasg = exists('../guide/' + whichstr + '.html')
hasb = exists('../background/' + whichstr + '.shtml')
hass = exists('../synops/' + whichstr + '.html')
hasc = exists('../credits/' + whichstr + '.html')
if exists(prev + '.html') or exists(prev + '.shtml'):
hasp = 1
else:
hasp = 0
if exists(next + '.html') or exists(next + '.shtml'):
hasn = 1
else:
hasn = 0
if page == 'comic' or page == 'novels':
hasb = 0
hass = 0
hasc = 0
return (hasg, hasb, hass, hasc, hasp, hasn)
#
# Generate a trio of navigational buttons for headers and footers.
#
def navbuttons(num, align = 'middle', which = 'guide'):
(hasg, hasb, hass, hasc, hasp, hasn) = getneighbors(num, which)
if which == 'background':
extension = '.shtml'
else:
extension = '.html'
curep = num
cureplong = '%03d' % (curep)
prevep = '%03d' % (curep - 1)
nextep = '%03d' % (curep + 1)
if which == 'comic' or which == 'novels':
output = """
"""
else:
output = """
"""
if hasp:
output=output+ """
"""
else:
output = output + """
"""
if hasn:
output=output+ """
"""
else:
output = output + """
"""
return output
#
# Devise a page header based on the current episode number and which page
# we're making.
#
def pageheader(num, page, do_jpeg = 0):
(hasg, hasb, hass, hasc, hasp, hasn) = getneighbors(num, page)
curep = num
cureplong = '%03d' % (curep)
prevep = '%03d' % (curep - 1)
nextep = '%03d' % (curep + 1)
if page == 'comic':
titleprefix = 'c'
titlewidth = 422
picname = 'comic/' + cureplong
elif page == 'novels':
titleprefix = 'n'
titlewidth = 427
picname = 'novels/' + cureplong
else:
titleprefix = 'e'
titlewidth = 340
pix = open('../internal/picnames', 'r')
for i in range(0, curep + 1):
picname = pix.readline()[:-1]
pix.close()
if picname == '':
picname = 'XXX'
if picname == 'none':
picname = 'tv-blank'
else:
picname = cureplong + '/' + picname
curep = repr(curep)
picwidth = 500 - titlewidth
output = """
"""
if page == 'comic' or page == 'novels':
output = output + ''
if do_jpeg and picname != 'tv-blank':
extension = '.jpeg'
else:
extension = '.gif'
output = output + """'
if page == 'comic' or page == 'novels':
output = output + ''
output = output + """
"""
if page == 'guide' or page == 'novels' or page == 'comic':
output = output + """
"""
else:
if hasg:
output = output + """
"""
else:
output = output + """
"""
if page == 'background':
output = output + """
"""
else:
if hasb:
output=output+ """
"""
else:
output = output + """
"""
if page == 'synopsis':
output = output + """
"""
else:
if hass:
output=output + """
"""
else:
output = output + """
"""
if page == 'credits':
output = output + """
"""
else:
if hasc:
output=output+ """
"""
else:
output = output + """
"""
output = output + navbuttons(num, 'middle', page) + "\n
![]()
![]()
![]()
"""
output = output + navbuttons(num, 'bottom', page) + '\n