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:]: for r in lines[1:]:
r = r.replace("\n","") r = r.replace("\n","")
r = r.replace("\r", "") r = r.replace("\r", "")
cells = r.split(",") # chomp newline cells = r.split(",") # chomp newline
(name, surname, guest, vfho, mug) = cells[:5] (name, surname, guest, vfho, mug) = cells[:5]
years = cells[5:] years = cells[5:]
expos_caving = len([t for t in years if t == "1"]) expos_caving = len([t for t in years if t == "1"])
expos_notcaving = 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): if(expos_caving == 0 and expos_notcaving == 0):
sys.stderr.write("Error processing " + name + ". No attendances found\n") sys.stderr.write("Error processing " + name + ". No attendances found\n")
sys.exit(1) sys.exit(1)
if(expos_caving and name != 'Rover Richardson' and name != 'Bier Tent'): headcount += 1 if(expos_caving and name != 'Rover Richardson' and name != 'Bier Tent'): headcount += 1
if mug: pics +=1 if mug: pics +=1
output += '<tr><td>' output += '<tr><td>'
if expos_caving == 0: output += '<span class="didntcave">' if expos_caving == 0: output += '<span class="didntcave">'
# Middle names still not working: MorvenBeranek-Stanley , Sarah Livia Zerbes # Middle names still not working: MorvenBeranek-Stanley , Sarah Livia Zerbes
# Need to manage names e.g. <span lang=""sv"">Leif Hornsved (Nickname)</span> => LeifHornsved # Need to manage names e.g. <span lang=""sv"">Leif Hornsved (Nickname)</span> => LeifHornsved
namevis = name.replace('""', '"').strip('"') namevis = name.replace('""', '"').strip('"')
# Need to manage e.g.Olaf K&auml;hler # Need to manage e.g.Olaf K&auml;hler
# Need to manage e.g. Bal%26aacute%3BzsIzapy # Need to manage e.g. Bal%26aacute%3BzsIzapy
nameurl = namevis.replace(' ', '') nameurl = namevis.replace(' ', '')
nameurl = nameurl.replace('&', '%26') nameurl = nameurl.replace('&', '%26')
nameurl = nameurl.replace(';', '%3B') nameurl = nameurl.replace(';', '%3B')
nameurl = re.sub('<[^>]*>','',nameurl) nameurl = re.sub('<[^>]*>','',nameurl)
nameurl = re.sub('\([^\)]*\)','',nameurl) # mostly noit needed, but is for Wookey nameurl = re.sub('\([^\)]*\)','',nameurl) # mostly noit needed, but is for Wookey
namelink= "<a href='/person/" + nameurl + "'>" + namevis + "</a>" namelink= "<a href='/person/" + nameurl + "'>" + namevis + "</a>"
output += namelink output += namelink
#output += name.replace('""', '"') #output += name.replace('""', '"')
if expos_caving == 0: output += '</span>' if expos_caving == 0: output += '</span>'
output += '</td><td>' output += '</td><td>'
if guest: output += '&sect;' if guest: output += '&sect;'
output += '</td><td>' output += '</td><td>'
if vfho: output += '&curren;' if vfho: output += '&curren;'
output += '</td><td>' output += '</td><td>'
if mug: if mug:
if not (os.path.isfile(mug)): if not (os.path.isfile(mug)):
print >> sys.stderr, "ERROR: --------------- mug file does not exist: ", 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 if mug: output += '<a href=%s><img alt=":-)" src="i/mug.png" /></a>' % mug
output += '</td>' output += '</td>'
for y in xrange(len(years)): for y in range(len(years)):
if(years[y]): if(years[y]):
m = str(76 + y)[-2:] m = str(76 + y)[-2:]
if(years[y]=='-1'): if(years[y]=='-1'):
m = '<span class="didntcave">'+ m + '</span>' m = '<span class="didntcave">'+ m + '</span>'
else: else:
try: try:
headcounts_byyear[y] += 1 headcounts_byyear[y] += 1
except IndexError: except IndexError:
sys.stderr.write(repr(r) +":::"+ str(y) + "\n") sys.stderr.write(repr(r) +":::"+ str(y) + "\n")
raise raise
output += '<td class="nonempty">' + m + '</td>' output += '<td class="nonempty">' + m + '</td>'
else: else:
output += '<td></td>' output += '<td></td>'
# print number of expos, non-caving in red. Only print numbers > 0 # print number of expos, non-caving in red. Only print numbers > 0
output += '<td style="text-align: right; width:36px; font-size:85%">' output += '<td style="text-align: right; width:36px; font-size:85%">'
if(expos_notcaving): if(expos_notcaving):
if(expos_caving): if(expos_caving):
output += '%d+<span class="didntcave">%d</span>' % (expos_caving, expos_notcaving) output += '%d+<span class="didntcave">%d</span>' % (expos_caving, expos_notcaving)
else: else:
output += '<span class="didntcave">%d</span>' % expos_notcaving output += '<span class="didntcave">%d</span>' % expos_notcaving
else: else:
output += '%d' % expos_caving output += '%d' % expos_caving
output += '</td></tr>\n' output += '</td></tr>\n'
recordholders.append((expos_caving, name)) recordholders.append((expos_caving, name))
def collapse(m): def collapse(m):
n = (m.span()[1]-m.span()[0]) / 9 n = (m.span()[1]-m.span()[0]) / 9
if(n == 1): return m.group() if(n == 1): return m.group()
else: return '<td colspan="%d"></td>' % n else: return '<td colspan="%d"></td>' % n
#output = re.sub(r'(<td></td>)+',collapse, output) #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 # moved to main.css
#<style type="text/css"> #<style type="text/css">
#.didntcave { color: #dd0000 } #.didntcave { color: #dd0000 }
print """ print("""
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
@ -106,8 +106,8 @@ print """
<title>CUCC's Austria expeditions: Members</title> <title>CUCC's Austria expeditions: Members</title>
<link rel="stylesheet" type="text/css" href="../css/main2.css" /> <link rel="stylesheet" type="text/css" href="../css/main2.css" />
<!-- <!--
table.fancy { border-collapse: collapse; border: 2px solid black } table.fancy { border-collapse: collapse; border: 2px solid black }
table.fancy td { border: 1px solid black; padding: 2pt } table.fancy td { border: 1px solid black; padding: 2pt }
table.fancy td.nonempty { background: #eee } table.fancy td.nonempty { background: #eee }
--> -->
</style> </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" --> <!-- 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> <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 <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 (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> 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 Gunter Graf, Sepp
Steinberger and Robert Seebacher <a href="i/seebacher2.jpg"><img alt=":-)" Steinberger and Robert Seebacher <a href="i/seebacher2.jpg"><img alt=":-)"
src="i/mug.png" /></a>.</p> 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 y2 = lastyear-2
y1 = lastyear-1 y1 = lastyear-1
print """ print("""
<p>Links to recent expos: <a href="http://expo.survex.com/expedition/%s">last year</a> <p>Links to recent expos: <a href="http://expo.survex.com/expedition/%s">last year</a>
<hr /><table class="fancy"> <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: 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> <td></td></tr>
</table> </table>
<hr /> <hr />
@ -174,23 +174,23 @@ print """
taken part in expo altogether (not counting non-combatants or vehicles(!)), taken part in expo altogether (not counting non-combatants or vehicles(!)),
of whom %d have their pictures on the site so far.</p> 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.sort()
recordholders.reverse() recordholders.reverse()
k = 2 k = 2
while recordholders[k + 1][0] == recordholders[k][0]: while recordholders[k + 1][0] == recordholders[k][0]:
k = k + 1 k = k + 1
print "%s (%d expos)," % (recordholders[0][1],recordholders[0][0]) print("%s (%d expos)," % (recordholders[0][1],recordholders[0][0]))
for r in recordholders[1:k]: 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 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 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 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 to be said for it. With draughts reversed in the cold, top entrances should
@ -201,4 +201,4 @@ remain open all winter.</p>
<hr /> <hr />
</body> </body>
</html>""" </html>""")