def getSingleTemplate(): single_span = SPAN(dclass="songtitle", content="${SINGLE_TITLE}") + BR() + SPAN( dclass="subtitle", content="${SINGLE_SUBTITLE}") prev_link = A(href="${PREVID}.html", content=IMG(src="/pix/left_arrow.gif", border="0", alt="previous single", title="previous single")) next_link = A(href="${NEXTID}.html", content=IMG(src="/pix/right_arrow.gif", border="0", alt="next single", title="next single")) title_bar = DIV(dclass="single_title", content=TABLE( dclass="single_title", content=TR( TD(content=prev_link, dclass="left_arrow") + TD(dclass="songtitle", content=single_span) + TD(content=next_link, dclass="right_arrow")))) issues = DIV(content="${ISSUES}") return Template( getBaseTemplate("singles").substitute( EXTRA_HEADER="", PAGE_TITLE="Elton John Single: ${SINGLE_TITLE}", PAGE_CONTENT=title_bar + issues + title_bar, ))
def getImportIndex(): return Template( getAlbumTemplate("Unauthorized").substitute( EXTRA_HEADER="", PAGE_TITLE="Elton John Unauthorized CDs", PAGE_CONTENT=BR().join([ "${TITLE}", "${DESCR}", "${NAVBAR}", "${ALBUMS}", "${NAVBAR}" ])))
def getGuestIndex(): return Template( getAlbumTemplate("Appearances").substitute( EXTRA_HEADER="", PAGE_TITLE="Elton John Guest Apperances", PAGE_CONTENT=BR().join([ "${TITLE}", "${DESCR}", "${NAVBAR}", "${ALBUMS}", "${NAVBAR}" ])))
def parse_guest_appearances(): records = 0 picpath = location.docroot + "albums/appearances/pix/" guestAlbums = ET.parse(location.dbroot + 'guest.xml').getroot() index_rows = [] for album in guestAlbums: if album.tag == 'description': guest_description = ET.tostring(album) continue if album.get('private'): continue records += 1 if album.tag == "single": title = SPAN(dclass="title", content="[single]") if album.tag == "album": title = SPAN(dclass="title", content=album.get('title')) artist = SPAN(dclass="gartist", content="(" + album.get('artist') + ")") if not artist: print "missing artist for album", album.get('title') if not title: print "missing title for album by", artist year = "(" + album.get('year')[:4] + ")" if not year: year = "(unknown)" pic = album.get('pic') if not pic: picTD = TD(dclass="missing_sleeve", content="[photo not available]") print title, "missing guest pic", artist pic = "NA" picfile = picpath + pic if os.path.isfile(picfile): (type, width, height) = getImageInfo(picfile) picTD = TD(dclass="single_sleeve", content=IMG(dclass="sleeve", src="pix/" + pic, width=width, height=height)) else: picTD = TD(dclass="missing_sleeve", content="[photo not available]") print "ERROR: can't find guest picture:", title, album.get( 'artist') amazon = album.get('amazon') if amazon: amazon = templates.getAmazonButton(amazon) else: amazon = "" trackrows = [] notes = [] for track in album: if track.tag == 'issue': continue if track.tag == 'note': notes.append(track.text) continue length = track.get('length') or "#:##" containsTD = TD(dclass="top", content="contains:") textTD = TD(dclass="track", content=linkTrack(track)) trackrows.append(TR(containsTD + textTD)) tracktable = TABLE("\n".join(trackrows)) detailsText = " ".join([title, artist]) detailsText += BR() + year + BR() + amazon + BR() + BR().join(notes) detailsTD = TD(dclass="guest_text", content=detailsText + BR() + tracktable) guest_entry = TABLE(TR(picTD + detailsTD)) index_rows.append(DIV(dclass="bubble", content=guest_entry)) # figure out how many index pages we need to create max_rows_per_index = 20 total_index_pages = len(index_rows) / max_rows_per_index if len(index_rows) % max_rows_per_index > 0: total_index_pages += 1 # chop away at the index_rows list, moving them into the current index page guestroot = location.docroot + "albums/appearances/" for page in range(total_index_pages): my_rows = index_rows[: max_rows_per_index] # grab the rows that go into this index page del index_rows[:max_rows_per_index] # clean up as we go guest_index_text = templates.getGuestIndex().substitute( TITLE=DIV(dclass="heading padded10", content="Elton John Guest Appearances"), DESCR=DIV(dclass="description", content=guest_description), ALBUMS=DIV(dclass="full_width", content="\n\n".join(my_rows)), #NAVBAR = DIV(content=DIV(content=" ".join(navDots))), NAVBAR=templates.getDotsDiv(page, total_index_pages), ) suffix = str(page + 1) if page == 0: suffix = "" with open(guestroot + "index" + suffix + ".html", "w") as guestindex: guestindex.write(guest_index_text) return records
def generate_session_albums(): totalAlbums = 0 loadTracks(location.dbroot + "album_tracks.xml") sessionroot = location.docroot + "albums/sessions/" picroot = sessionroot + "pix/" root = XML.parse(location.dbroot + 'sessionwork.xml').getroot() totalrecords = 0 description = root.find('description') #description = description.text description = XML.tostring(description) index_rows = [] songrows = [] songrows.append( TR( TD(B(U("released"))) + TD(B(U("title"))) + TD(B(U("original artist"))))) for song in root.findall('listing/song'): year = song.get('date')[:4] month = song.get('date')[5:7] month = monthAbbreviation[month] eltonvocals = song.get('elton', default="lead vocals") eltonvocals = " [" + eltonvocals + "]" songrow = TR( TD(month + " " + year) + TD(B(U(song.get('title'))) + eltonvocals) + TD(song.get('artist'))) songrows.append(songrow) songtable = DIV(dclass="bubble", content=TABLE(content="\n".join(songrows), dclass="left small")) description += songtable for category in root.findall('category'): if category.get('private'): continue format = category.get('format') categoryname = category.get('format') for issue in category: if issue.get('private'): continue #if issue.get('pic') == None: continue totalrecords += 1 title = issue.get('title') if title == None: title = "" if format == "7": title = "7-inch single" if format == "CD5": title = "CD single" catalog = issue.get('catalog') if catalog == None: print "no catalog for", title continue pic = issue.get('pic') if pic == None: picTD = TD(dclass="missing_sleeve", content="[no sleeve]") else: picfile = picroot + pic if os.path.isfile(picfile): (type, width, height) = getImageInfo(picfile) picTD = TD(dclass="single_sleeve", content=IMG(dclass="sleeve", src="pix/" + pic, width=width, height=height)) else: picTD = TD(dclass="missing_sleeve", content="[photo not available]") print "ERROR: can't find session picture:", title, catalog year = issue.get('year', default="") if len(year): year = " (" + year[:4] + ")" trackrows = [] for track in issue.findall('track'): if track.get('artist') == "anonymous": trackrows.append( LI(dclass="anonymous", content=track.get('title'))) else: trackrows.append( LI(dclass="track", content=linkTrack(track))) reftracks = [] for element in issue: if element.tag == 'tracks': reftracks = reftracks + alltracks[element.get('id')] for track in reftracks: trackrows.append(LI(dclass="track", content=linkTrack(track))) prefix = issue.get('discs', "") iconfile = "/pix/" + prefix + format + ".gif" (type, width, height) = getImageInfo(location.docroot + iconfile) icon = IMG(dclass="padded10", src=iconfile, width=width, height=height) notes = "" for note in issue.findall('note'): notes += BR() + note.text tracktable = OL("\n".join(trackrows)) title = DIV(dclass="large bold", content=title) detailsText = icon + title + catalog + year + notes detailsTD = TD(dclass="guest_text", content=detailsText + BR() + tracktable) session_issue = TABLE(TR(picTD + detailsTD)) index_rows.append(DIV(dclass="bubble", content=session_issue)) session_index_text = templates.getSessionIndex().substitute( TITLE=DIV(dclass="heading padded10", content="Elton John as a Session Musician"), DESCR=DIV(dclass="description", content=description), ALBUMS=DIV(dclass="full_width", content="\n\n".join(index_rows)), ) with open(sessionroot + "index.html", "w") as sessionindex: sessionindex.write(session_index_text.encode('latin-1')) return totalrecords
def getSessionIndex(): return Template( getAlbumTemplate("Session").substitute( EXTRA_HEADER="", PAGE_TITLE="Elton John as a Session Musician", PAGE_CONTENT=BR().join(["${TITLE}", "${DESCR}", "${ALBUMS}"])))
def generate_singles(): singles_root = location.docroot + "singles/" # ---------------------------------------------------------------------------- # Collect href information for albums, to verify album linking. Dictionary is # fileID -> title_string # ---------------------------------------------------------------------------- #album_ids = {} #albums = ET.parse(location.dbroot+'category_albums.xml').getroot() #for album in albums: # album_ids[album.get('id')] = album.get('title') #albums = ET.parse(location.dbroot+'other_albums.xml').getroot() #for album in albums: # album_ids[album.get('id')] = album.get('title') xmldoc = ET.parse(location.dbroot+'singles.xml').getroot() # load singles from file # ---------------------------------------------------------------------------- # Set the id/prev/next links as XML attributes. # ---------------------------------------------------------------------------- prevsingle = None for single in xmldoc: if single.get('artist') : continue # some other artist single if single.get('private') : continue # not for public website if single.tag == 'description': description = single.text continue if single.tag == 'break' : continue if single.tag == 'single' : # get the id from the title id = re.sub(' ', '_', single.get('title')).lower() id = re.sub('\(', '', id) id = re.sub('\)', '', id) id = re.sub('\/',' ', id) id = re.sub('\'', "", id) single.set('id', re.sub(' ', '_', id)) if single.tag == 'miscellaneous' : single.set('id', re.sub(' ','_',single.get('country').lower())) if prevsingle != None: prevsingle.set('nextid',single.get('id')) # forward link single.set('previd',prevsingle.get('id')) # backward link else : firstsingle = single # save first for linnking with last prevsingle = single single.set('nextid', firstsingle.get('id')) # fully cycled double linked-list firstsingle.set('previd', single.get('id')) # fully cycled double linked-list # ---------------------------------------------------------------------------- # Store each single as its own HTML file with listing of issues. Also # generate index pages. # ---------------------------------------------------------------------------- picpath = singles_root + "pix/" flagpath = location.docroot + "/pix/flags/" index_rows = [] # prepare list for index page total_issues = 0 # prepare info for index page total_pages = 0 for single in xmldoc: if single.tag == 'description': continue # already got this if single.get('artist'): continue # ignore singles by non-Elton artists if single.get('private'): continue # ignore singles not intended for public total_pages += 1 icon=None # should be populated later if single.tag == 'single': title = single.get('title') subtitle = '('+single.get('release')[0:4] + ')' (type,width,height) = getImageInfo(picpath+'icons/'+single.get('icon')) single_icon=IMG(src="pix/icons/"+single.get('icon'), width=width, height=height, alt=title, dclass="single_icon") elif single.tag == 'break': index_rows.append(DIV(dclass="bubble description", content=single.text)) continue elif single.tag == 'miscellaneous' : title = single.get('country')+" unique singles" subtitle = "(miscellaneous releases)" flag = re.sub(' ','_',single.get('country').lower()) + ".gif" if not os.path.isfile(flagpath+flag): print "ERROR missing flag for",country (type,width,height) = getImageInfo(flagpath+flag) single_icon = IMG(src="/pix/flags/"+flag, width=width, height=height, alt=title, dclass="single_icon") #print "parsing",title # TBD... #if single.get('album') : # album_href = "/albums/"+single.get('album')+".html" # album_title = album_ids.get(single.get('album')) # albumlink = "From the album " + A(href=album_href, content=album_title) # #subtitle += '<br/>('+albumlink+')' issues = [] for issue in single: if issue.get('private'): continue # not for website if issue.get('format') == "CS": continue # not for website yet total_issues += 1 # info for index page country = issue.get('country') if country == None: print "ERROR missing country" count = single.get('count') if count: count = int(count)+1 else: count = 1 single.set('count',str(count)) # detect flag GIF based on country flag = re.sub(' ','_',country.lower()) + ".gif" if not os.path.isfile(flagpath+flag): print "ERROR missing flag for",country (type,width,height) = getImageInfo(flagpath+flag) flagpic = IMG(src="/pix/flags/"+flag, width=width, height=height, alt=country, title=country) if single.tag == 'miscellaneous': flagpic="" # flag for misc issues is redundant format = issue.get('format') if format == None: print "ERROR missing format" if format == 'postcard': continue # ignore Polish cards for now year = issue.get('year') if year == 'unknown': year = "" if year == None: print "ERROR missing year" catalog = issue.get('catalog') if catalog == None: print "ERROR missing catalog" promo = "" if issue.get('promo'): promo = '[promo]' discs = "" if issue.get('discs'): discs = '[' + issue.get('discs') + ' discs]' note = "" if issue.get('note') : note = '[' + issue.get('note') + ']' if not issue.get('ps'): sleeve = "" picTD = TD(dclass="missing_sleeve", content="(no sleeve)") else: if issue.get('ps') == 'true' : sleeve = "[picture sleeve]" else : sleeve = '[' + issue.get('ps') + ']' pic = re.sub('/','',catalog).upper() pic = '/'.join([format,country,pic]) if issue.get('pic'): pic = "/".join([format,issue.get('pic')]) pic = re.sub(' ','_',pic) pic = re.sub('-','',pic) pic = re.sub('\.','',pic) if issue.get('pic') : pic = '/'.join([format,issue.get('pic')]) picfile = None if os.path.isfile(picpath+pic+".jpg"): picfile = "pix/"+pic+".jpg" elif os.path.isfile(picpath+pic+".gif"): picfile = "pix/"+pic+".gif" if picfile: (type,width,height) = getImageInfo(singles_root + picfile) picTD = TD(dclass="single_sleeve", content=IMG(dclass="sleeve", src=picfile, width=width, height=height) + BR() + sleeve) else: picTD = TD(dclass="missing_sleeve", content="[sleeve photo not available]") if issue.get('pic') != "NA": print "ERROR: can't find picture:",issue.get('pic'), title, format, country, year, catalog if os.path.isfile(singles_root + "pix/"+format+".gif"): icon = IMG(src="pix/"+format+".gif") # use graphical icon else: icon = format # use text name country = "("+country+")" if single.tag == 'miscellaneous': country = "" issueheader = TR(TD(dclass="single_details", colspan=2, content=" ".join([icon,year,catalog,country,discs,promo,note]))) trackrows = [] trackrows.append(issueheader) for track in issue: tracktime = TD(dclass="time", content=track.get('length')) tracktext = TD(dclass="track", content=linkTrack(track)) trackrows.append(TR(tracktime + tracktext)) tracktable = TABLE("\n".join(trackrows)) detailsTD = TD(tracktable) issues.append(DIV(dclass="bubble", content=TABLE(dclass="single_issue", content=TR(picTD + detailsTD)))) page_template = templates.getSingleTemplate() single_text = page_template.substitute( NEXTID = single.get('nextid'), PREVID = single.get('previd'), SINGLE_TITLE = '"'+title+'"', SINGLE_SUBTITLE = subtitle, ISSUES = "\n".join(issues) ) target = single.get('id')+".html" with open(singles_root+target, "w") as singlefile: singlefile.write(single_text.encode('latin1')) count = single.get('count') suffix = "" if count > 1: suffix = "s" subtitle = SPAN(dclass="single_count",content=subtitle + BR()+'(' + count + ' pressing'+suffix+')') iconTD = TD(dclass="single_icon", content=A(href=target, content=single_icon)) textTD = TD(dclass="single_index", content=SPAN(dclass="single_index", content=A(href=target, content=title)) + subtitle) index_rows.append(DIV(dclass="bubble", content=TABLE(TR(iconTD + textTD)))) #TBD index_rows.append(TR(TD("total worldwide pressings: " + str(total_issues)))) # ---------------------------------------------------------------------------- # Now write set of index pages that links to all the other single pages. # ---------------------------------------------------------------------------- max_rows_per_index = 30; total_index_pages = len(index_rows)/max_rows_per_index if len(index_rows) % max_rows_per_index > 0: total_index_pages += 1 for page in range(total_index_pages) : navDots=[] for link in range(total_index_pages) : suffix = str(link+1) if link == 0: suffix = "" if link == page: navDots.append(IMG(dclass="navdots", src="/pix/white_dot.gif")) else: navDots.append(A(href="index"+suffix+".html", alt="page "+suffix, content=IMG(dclass="noborder navdots", border="0", src="/pix/green_dot.gif"))) my_rows = index_rows[:max_rows_per_index] del index_rows[:max_rows_per_index] single_index_text = templates.getSingleIndex().substitute( TITLE = DIV(dclass='heading padded10', content="Elton John Singles"), DESCR = DIV(dclass='description', content=description), ISSUES = "\n".join(my_rows), NAVBAR = DIV(content=DIV(content=" ".join(navDots))), ) suffix = str(page+1) if page == 0: suffix = "" with open(singles_root+"index"+suffix+".html", "w") as singleindex: singleindex.write(single_index_text) return total_issues