-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
83 lines (70 loc) · 2.01 KB
/
main.py
File metadata and controls
83 lines (70 loc) · 2.01 KB
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
77
78
79
80
81
82
83
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Script to parse and process a game transcript from 18xx.games.
Features
--------
* Parses a transcript file for a specified 18xx game (e.g. 1830, 1889).
* Optionally runs full verification of the final game state based on a ground
truth file.
Usage
-----
$ python main.py G1830 transcript.txt [--skip-verify]
Args
----
* game The game identifier used to select game rules.
* transcript Path to the text file containing the transcript.
* --skip-verify Skips final game state verification.
* --debug Enable debug output in logger.
"""
import argparse
import json
import logging
from pathlib import Path
import transcripts18xx as trx
def parse_arguments():
parser = argparse.ArgumentParser(
description='Process a game transcript from 18xx.games'
)
parser.add_argument(
'game',
type=trx.Games.argparse,
choices=trx.Games,
help='Game type of transcript, e.g. G1830',
)
parser.add_argument(
'transcript',
type=Path,
help='Path to the game transcript'
)
parser.add_argument(
'--skip-verify',
action='store_true',
help='Skip the verification of the final state'
)
parser.add_argument(
'--debug',
action='store_true',
help='Enable debug output of logger'
)
return parser.parse_args()
def main():
args = parse_arguments()
level = logging.INFO
if args.debug:
level = logging.DEBUG
logging.basicConfig(
level=level,
format='%(asctime)s [%(threadName)s] %(levelname)s: %(message)s',
handlers=[
logging.FileHandler('main.log', mode='w'),
logging.StreamHandler()
]
)
game = args.game.select()
parser = trx.TranscriptParser(args.transcript, game)
result = parser.parse()
print(json.dumps(result, indent=2))
if not args.skip_verify:
trx.full_verification(args.transcript)
if __name__ == '__main__':
main()