python3 2to3 conversion

This commit is contained in:
Philip Sargent 2020-05-26 01:35:20 +01:00
parent 7223a746bf
commit 07bde0ae9b

View File

@ -19,76 +19,76 @@ headcounts_byyear = [0]*(len(lines[0].split(","))-5)
for r in lines[1:]:
r = r.replace("\n","")
r = r.replace("\r", "")
cells = r.split(",") # chomp newline
(name, surname, guest, vfho, mug) = cells[:5]
years = cells[5:]
expos_caving = len([t for t in years if t == "1"])
expos_notcaving = len([t for t in years if t == "-1"])
if(expos_caving == 0 and expos_notcaving == 0):
sys.stderr.write("Error processing " + name + ". No attendances found\n")
sys.exit(1)
if(expos_caving and name != 'Rover Richardson' and name != 'Bier Tent'): headcount += 1
if mug: pics +=1
output += '<tr><td>'
if expos_caving == 0: output += '<span class="didntcave">'
r = r.replace("\n","")
r = r.replace("\r", "")
cells = r.split(",") # chomp newline
(name, surname, guest, vfho, mug) = cells[:5]
years = cells[5:]
expos_caving = len([t for t in years if t == "1"])
expos_notcaving = len([t for t in years if t == "-1"])
if(expos_caving == 0 and expos_notcaving == 0):
sys.stderr.write("Error processing " + name + ". No attendances found\n")
sys.exit(1)
if(expos_caving and name != 'Rover Richardson' and name != 'Bier Tent'): headcount += 1
if mug: pics +=1
output += '<tr><td>'
if expos_caving == 0: output += '<span class="didntcave">'
# Middle names still not working: MorvenBeranek-Stanley , Sarah Livia Zerbes
# Need to manage names e.g. <span lang=""sv"">Leif Hornsved (Nickname)</span> => LeifHornsved
namevis = name.replace('""', '"').strip('"')
# Need to manage e.g.Olaf K&auml;hler
# Need to manage e.g. Bal%26aacute%3BzsIzapy
nameurl = namevis.replace(' ', '')
nameurl = nameurl.replace('&', '%26')
nameurl = nameurl.replace(';', '%3B')
nameurl = re.sub('<[^>]*>','',nameurl)
nameurl = re.sub('\([^\)]*\)','',nameurl) # mostly noit needed, but is for Wookey
namelink= "<a href='/person/" + nameurl + "'>" + namevis + "</a>"
output += namelink
#output += name.replace('""', '"')
# Middle names still not working: MorvenBeranek-Stanley , Sarah Livia Zerbes
# Need to manage names e.g. <span lang=""sv"">Leif Hornsved (Nickname)</span> => LeifHornsved
namevis = name.replace('""', '"').strip('"')
# Need to manage e.g.Olaf K&auml;hler
# Need to manage e.g. Bal%26aacute%3BzsIzapy
nameurl = namevis.replace(' ', '')
nameurl = nameurl.replace('&', '%26')
nameurl = nameurl.replace(';', '%3B')
nameurl = re.sub('<[^>]*>','',nameurl)
nameurl = re.sub('\([^\)]*\)','',nameurl) # mostly noit needed, but is for Wookey
namelink= "<a href='/person/" + nameurl + "'>" + namevis + "</a>"
output += namelink
#output += name.replace('""', '"')
if expos_caving == 0: output += '</span>'
output += '</td><td>'
if guest: output += '&sect;'
output += '</td><td>'
if vfho: output += '&curren;'
output += '</td><td>'
if mug:
if not (os.path.isfile(mug)):
print >> sys.stderr, "ERROR: --------------- mug file does not exist: ", mug
if mug: output += '<a href=%s><img alt=":-)" src="i/mug.png" /></a>' % mug
output += '</td>'
for y in xrange(len(years)):
if(years[y]):
m = str(76 + y)[-2:]
if(years[y]=='-1'):
m = '<span class="didntcave">'+ m + '</span>'
else:
try:
headcounts_byyear[y] += 1
except IndexError:
sys.stderr.write(repr(r) +":::"+ str(y) + "\n")
raise
output += '<td class="nonempty">' + m + '</td>'
else:
output += '<td></td>'
if expos_caving == 0: output += '</span>'
output += '</td><td>'
if guest: output += '&sect;'
output += '</td><td>'
if vfho: output += '&curren;'
output += '</td><td>'
if mug:
if not (os.path.isfile(mug)):
print("ERROR: --------------- mug file does not exist: ", mug, file=sys.stderr)
if mug: output += '<a href=%s><img alt=":-)" src="i/mug.png" /></a>' % mug
output += '</td>'
for y in range(len(years)):
if(years[y]):
m = str(76 + y)[-2:]
if(years[y]=='-1'):
m = '<span class="didntcave">'+ m + '</span>'
else:
try:
headcounts_byyear[y] += 1
except IndexError:
sys.stderr.write(repr(r) +":::"+ str(y) + "\n")
raise
output += '<td class="nonempty">' + m + '</td>'
else:
output += '<td></td>'
# print number of expos, non-caving in red. Only print numbers > 0
output += '<td style="text-align: right; width:36px; font-size:85%">'
if(expos_notcaving):
output += '<td style="text-align: right; width:36px; font-size:85%">'
if(expos_notcaving):
if(expos_caving):
output += '%d+<span class="didntcave">%d</span>' % (expos_caving, expos_notcaving)
else:
output += '<span class="didntcave">%d</span>' % expos_notcaving
else:
output += '%d' % expos_caving
else:
output += '%d' % expos_caving
output += '</td></tr>\n'
recordholders.append((expos_caving, name))
recordholders.append((expos_caving, name))
def collapse(m):
n = (m.span()[1]-m.span()[0]) / 9
if(n == 1): return m.group()
else: return '<td colspan="%d"></td>' % n
n = (m.span()[1]-m.span()[0]) / 9
if(n == 1): return m.group()
else: return '<td colspan="%d"></td>' % n
#output = re.sub(r'(<td></td>)+',collapse, output)
@ -96,9 +96,9 @@ lastyear=1976+1+len([t for t in headcounts_byyear if t > 0]) # no expo in 1986
# moved to main.css
#<style type="text/css">
#.didntcave { color: #dd0000 }
#.didntcave { color: #dd0000 }
print """
print("""
<!DOCTYPE html>
<html>
<head>
@ -106,8 +106,8 @@ print """
<title>CUCC's Austria expeditions: Members</title>
<link rel="stylesheet" type="text/css" href="../css/main2.css" />
<!--
table.fancy { border-collapse: collapse; border: 2px solid black }
table.fancy td { border: 1px solid black; padding: 2pt }
table.fancy { border-collapse: collapse; border: 2px solid black }
table.fancy td { border: 1px solid black; padding: 2pt }
table.fancy td.nonempty { background: #eee }
-->
</style>
@ -117,9 +117,9 @@ table.fancy td.nonempty { background: #eee }
<!-- DO NOT EDIT THIS DOCUMENT BY HAND! It is automatically generated by "scripts/make-folklist.py" -->
<h1>CUCC members and guests in Austria</br> 1976 to %s</h1>
""" % lastyear
""" % lastyear)
print """
print("""
<p>This is a pretty much complete list of all the personnel on %d CUCC
expeditions (there was no expo in 1986), together with the total number of
expeditions each has attended and the total number of people on each expedition.</p>
@ -150,22 +150,22 @@ times. These include particularly Karl Gaisberger
Gunter Graf, Sepp
Steinberger and Robert Seebacher <a href="i/seebacher2.jpg"><img alt=":-)"
src="i/mug.png" /></a>.</p>
""" % len([t for t in headcounts_byyear if t > 0])
""" % len([t for t in headcounts_byyear if t > 0]))
y2 = lastyear-2
y1 = lastyear-1
print """
print("""
<p>Links to recent expos: <a href="http://expo.survex.com/expedition/%s">last year</a>
<hr /><table class="fancy">
""" % y1
""" % y1)
print output
print(output)
print "<tr><td colspan=4><strong>Expo head count</strong></td>",
print("<tr><td colspan=4><strong>Expo head count</strong></td>", end=' ')
for y in headcounts_byyear:
print '<td style="text-align: right">%d</td>' % y,
print('<td style="text-align: right">%d</td>' % y, end=' ')
print """
print("""
<td></td></tr>
</table>
<hr />
@ -174,23 +174,23 @@ print """
taken part in expo altogether (not counting non-combatants or vehicles(!)),
of whom %d have their pictures on the site so far.</p>
<p>Although few take <a href="/people">such statistics</a> seriously, the most dedicated expoers are """ % (headcount, pics)
<p>Although few take <a href="/people">such statistics</a> seriously, the most dedicated expoers are """ % (headcount, pics))
recordholders.sort()
recordholders.reverse()
k = 2
while recordholders[k + 1][0] == recordholders[k][0]:
k = k + 1
print "%s (%d expos)," % (recordholders[0][1],recordholders[0][0])
k = k + 1
print("%s (%d expos)," % (recordholders[0][1],recordholders[0][0]))
for r in recordholders[1:k]:
print "%s (%d)," % (r[1],r[0]),
print("%s (%d)," % (r[1],r[0]), end=' ')
print """and %s (%d). Julian Todd holds the record for consecutive
print("""and %s (%d). Julian Todd holds the record for consecutive
expo attendance (10), (along with Mark Shinwell, but he didn't actually
go caving on all of those visits). A more obscure record of longest gap between expos has been held by various people since 2004 at 13, and then 17, years, but in 2017 was upped to 34 years by Phil Sargent, which is going to be extremely hard to beat!</p>""" % (recordholders[k][1],recordholders[k][0])
go caving on all of those visits). A more obscure record of longest gap between expos has been held by various people since 2004 at 13, and then 17, years, but in 2017 was upped to 34 years by Phil Sargent, which is going to be extremely hard to beat!</p>""" % (recordholders[k][1],recordholders[k][0]))
print """<p>Outside-expo caving happens from time to time, with Becka Lawson, Neil Pacey, Julian Todd and Wookey
print("""<p>Outside-expo caving happens from time to time, with Becka Lawson, Neil Pacey, Julian Todd and Wookey
joining various Arge and VfHO trips since about 2000. However, the much talked-about
winter expedition/holiday has still not happened, though there is still a lot
to be said for it. With draughts reversed in the cold, top entrances should
@ -201,4 +201,4 @@ remain open all winter.</p>
<hr />
</body>
</html>"""
</html>""")