54 lines
1.4 KiB
Python
54 lines
1.4 KiB
Python
import argparse
|
|
import json
|
|
import os
|
|
import random
|
|
import sys
|
|
|
|
sys.path.insert(
|
|
0,
|
|
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
)
|
|
|
|
from mathpractice.sheet import Sheet
|
|
from mathpractice.html_formatter import HTMLFormatter
|
|
from mathpractice.json_formatter import JSONFormatter
|
|
|
|
|
|
def main(sysargs=sys.argv[:]):
|
|
parser = argparse.ArgumentParser(
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter
|
|
)
|
|
parser.add_argument('-L', '--lowest-factor', type=int, default=0)
|
|
parser.add_argument('-H', '--highest-factor', type=int, default=15)
|
|
parser.add_argument('-t', '--total', type=int, default=100)
|
|
parser.add_argument('-s', '--seed', type=float, default=random.random())
|
|
parser.add_argument(
|
|
'-f', '--format',
|
|
type=str, choices=('html', 'json'), default='html'
|
|
)
|
|
args = parser.parse_args(sysargs[1:])
|
|
|
|
sheet = Sheet.generate(
|
|
args.lowest_factor,
|
|
args.highest_factor,
|
|
total=args.total,
|
|
seed=args.seed
|
|
)
|
|
|
|
if args.format == 'html':
|
|
sys.stdout.write(
|
|
HTMLFormatter().format(sheet)
|
|
)
|
|
elif args.format == 'json':
|
|
sys.stdout.write(
|
|
JSONFormatter().format(sheet)
|
|
)
|
|
else:
|
|
raise ArgumentError('unknown format {}'.format(args.format))
|
|
sys.stdout.write('\n')
|
|
return 0
|
|
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(main())
|