#!/usr/bin/python
# A quick python script to generate progress of listening to LRL eps
import datetime, os
def make_hash(hashes):
# Returns 'n' hashes as a string
output = ''
for hash in range(1,20):
if (hash <= hashes):
output += '<img src="bar.png" alt="#" />'
else:
output += '<img src="nobar.png" alt="" />'
return output
date_of_lrl = datetime.datetime(2007,07,07)
today = datetime.datetime.today()
days_left = (date_of_lrl-today).days
max_shows = [12,23,24,17]
# HTML Headers
print "Content-type: text/html\n\n"
print
print """<html><head>
<meta author="Ben Thorp">
<meta generator="Custom Python Script">
<style type="text/css" media="screen">
@import url(http://www.jedimoose.org/wp-content/themes/scarylittle/styles.php );
</style>
<title>Listening to LugRadio before LRL07</title>
</head>
<body>
<h1>LugRadio Live 2007</h1>
<h4>The last couple of years I have endeavoured to listen to the entire LugRadio archive in the months running up to LugRadio. This year I started a bit late, and so I thought I would waste time by writing a quick Python script to help me keep track of my progress.</h4>
<br />
<table>"""
# if there is no show file, then generate it
if (os.path.exists(os.getcwd()+'/shows.txt')) :
data = open('shows.txt','r')
else:
data = open('shows.txt','w')
for seasons in range(len(max_shows)):
for episode in range(max_shows[seasons]):
data.write(' Season'+str(seasons+1)+' Episode'+str(episode+1)+'\n')
data.close
data = open('shows.txt', 'r')
showlist = data.readlines()
output = ""
count = 0
totalcount = 0
totalshows = sum(max_shows)
for seasons in range(len(max_shows)):
tempcount = 0
for episode in (range(max_shows[seasons])):
if showlist[count][0] != ' ':
tempcount += 1
totalcount += 1
count += 1
percentage = float(tempcount) / (float(max_shows[seasons])/100.0)
hashes = int(percentage / 5)
output += "<tr><td>Season "+str(seasons+1)+"</td><td>("+str(int(percentage))+"%)</td>"
output += "<td>"+make_hash(hashes)+"</td></tr>"
output += "\n"
percentage = float(totalcount) / (float(totalshows)/100.0)
hashes = int(percentage / 5)
output += "<tr><td>Total</td><td>("+str(int(percentage))+"%)</td><td>"+make_hash(hashes)+"</td></tr></table><br />\n"
output += "<p>"+str(days_left)+" days left, meaning "+str(round((float(totalshows)-float(totalcount))/float(days_left), 2))+" shows per day</p>\n"
output += """<br /><a href="http://www.python.org"><img src="python.png" alt="python powered" /></a><a href="http://www.lugradio.org/live"><img src="lrl2007.jpg" alt="LugRadio Live 2007" /></a><br /><a href="listener.html">See the code</a></body></html>"""
print output