eliot/extras/reports/stats.py
Olivier Teulière 6fbd7febb0 Reports: initial version, with 2 reports.
The reports are already usable, but the statistics report could be
improved.
2012-12-11 21:33:47 +01:00

32 lines
900 B
Python
Executable file

#!/usr/bin/env python
import os
import sys
import argparse
from Cheetah.Template import Template
# Eliot modules
import eliot
# Command-line parsing
parser = argparse.ArgumentParser(description="""Generate an HTML page roughly equivalent to the Statistics window in Eliot""")
parser.add_argument("-s", "--savegame", help="game saved with Eliot", type=file, required=True)
parser.add_argument("-o", "--output", help="output file (stdout by default)",
type=argparse.FileType('w'), default=sys.stdout)
args = parser.parse_args()
# Do most of the work: open the save game file, parse it,
# and build easy to use data structures
gameData = eliot.readSaveGame(args.savegame.name)
# Load the template
with file("stats.tmpl") as f:
templDef = f.read()
# Fill it with values
templ = Template(templDef, {'gameData': gameData})
# Print the generated document
args.output.write(str(templ));