diff --git a/html-src/gen-html.py b/html-src/gen-html.py index 21bedd37..1b7174bd 100755 --- a/html-src/gen-html.py +++ b/html-src/gen-html.py @@ -1,9 +1,9 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import sys import os import re -import __builtin__ +import builtins from pysollib.mygettext import fix_gettext from pysollib.gamedb import GAME_DB @@ -13,8 +13,8 @@ from pysollib.mfxutil import latin1_to_ascii pysollib_dir = '../' -__builtin__._ = lambda x: x -__builtin__.n_ = lambda x: x +builtins._ = lambda x: x +builtins.n_ = lambda x: x import pysollib.games import pysollib.games.mahjongg @@ -139,12 +139,14 @@ def getGameRulesFilename(n): def gen_main_html(): for infile, title in files: outfile = open(os.path.join('html', infile), 'w') - print >> outfile, main_header % title - print >> outfile, open(infile).read() + print(main_header % title, file=outfile) + with open(infile, 'r') as file: + print(file.read(), file=outfile) s = 'Back to the index' if infile == 'index.html': s = '' - print >> outfile, main_footer % s + print(main_footer % s, file=outfile) + outfile.close() def gen_rules_html(): @@ -167,8 +169,9 @@ def gen_rules_html(): # open file of list of all rules out_rules = open(os.path.join('html', 'rules.html'), 'w') - print >> out_rules, main_header % 'PySol - a Solitaire Game Collection' - print >> out_rules, open('rules.html').read() + print(main_header % 'PySol - a Solitaire Game Collection', file=out_rules) + with open('rules.html', 'r') as file: + print(file.read(), file=out_rules) for id in games: # create list of rules @@ -188,7 +191,7 @@ def gen_rules_html(): rules_dir = 'wikipedia' else: print('missing rules for %s (file: %s)' - % (gi.name.encode('utf-8'), rules_fn)) + % (gi.name, rules_fn)) continue # print '>>>', rules_fn @@ -208,34 +211,41 @@ def gen_rules_html(): rules_list.append((rules_dir, rules_fn, title, s)) files_list.append(rules_fn) # rules_list.append((rules_fn, gi.name)) - print >> out_rules, '