1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
# Fix lexicon .htm files included with iOS/Android/web Golly.
#
# We replace this text:
#
# <center><table cellspacing=0 cellpadding=0><tr><td><pre><a href="lexpatt:">
# .O.....
# ...O...
# OO..OOO
# </a></pre>etc...
#
# with:
#
# <center><table cellspacing=0 cellpadding=0><tr><td><pre><a href="lexpatt:.O.....$...O...$OO..OOO$">
# .O.....
# ...O...
# OO..OOO
# </a></pre></td></tr></table></center>
#
# We also increase font size used for links at top and bottom of each page.
import re
# ------------------------------------------------------------------------------
def fix_file(filename):
print 'fixing ' + filename
f = open(filename, 'r')
contents = f.read()
# use re.DOTALL to include newlines in match
for pattdata in re.findall('<a href="lexpatt:">\n(.*?)</a>', contents, re.DOTALL):
newdata = pattdata.replace('\n','$')
contents = contents.replace('<a href="lexpatt:">\n'+pattdata+'</a>',
'<a href="lexpatt:'+newdata+'"\n>'+pattdata+'</a>', 1)
# remove small font used for links at top and bottom of each page
contents = contents.replace('<font size=-1><b>', '<b>', 2)
contents = contents.replace('Z</A></b></font>', 'Z</A></b>', 2)
f.close()
f = open(filename, 'w')
f.write(contents)
f.close()
# ------------------------------------------------------------------------------
fix_file("lex.htm")
fix_file("lex_1.htm")
fix_file("lex_a.htm")
fix_file("lex_b.htm")
fix_file("lex_c.htm")
fix_file("lex_d.htm")
fix_file("lex_e.htm")
fix_file("lex_f.htm")
fix_file("lex_g.htm")
fix_file("lex_h.htm")
fix_file("lex_i.htm")
fix_file("lex_j.htm")
fix_file("lex_k.htm")
fix_file("lex_l.htm")
fix_file("lex_m.htm")
fix_file("lex_n.htm")
fix_file("lex_o.htm")
fix_file("lex_p.htm")
fix_file("lex_q.htm")
fix_file("lex_r.htm")
fix_file("lex_s.htm")
fix_file("lex_t.htm")
fix_file("lex_u.htm")
fix_file("lex_v.htm")
fix_file("lex_w.htm")
fix_file("lex_x.htm")
fix_file("lex_y.htm")
fix_file("lex_z.htm")
fix_file("lex_bib.htm")
|