summaryrefslogtreecommitdiff
path: root/deal-converter.py
blob: de0d01a2e0c27f4efd3e7187ba8887d66d6fd164 (plain)
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
from __future__ import print_function
import argparse, os, sys, warnings

from dealconvert import DealConverter

parser = argparse.ArgumentParser(
    description='Universal converter for bridge deal formats',
    formatter_class=argparse.RawTextHelpFormatter,
    epilog='Supported formats: BER BHG BRI CDS CSV DGE DLM DUP LIN PBN RZD.\n' + \
    'Formats are auto-detected based on file extension.\n' + \
    'To display deals on STDOUT, provide "-" as an output file name.\n' + \
    'To print deals to HTML file, use *.html output file.\n' + \
    'To print deals to PDF file, use *.pdf output file.\n\n' + \
    'PDF output requires wkhtmltopdf in a patched-qt version.')
parser.add_argument('--jfr', action='store_true',
                    help='For PBN file, write only JFR DD fields')
parser.add_argument('--columns', type=int, default=None,
                    help='For HTML and PDF files, print-out column count')
parser.add_argument('--orientation', type=str,
                    choices=['Landscape', 'Portrait'], default=None,
                    help='For PDF files, page orientation')
parser.add_argument('input', metavar='INPUT_FILE',
                    help='Input file path')
parser.add_argument('output', metavar='OUTPUT_FILE', nargs='*',
                    help='Output file path(s)')

arguments = parser.parse_args()

def _warning(msg, *args, **kwargs):
    print('WARNING: %s' % (msg), file=sys.stderr)
warnings.showwarning = _warning

try:
    converter = DealConverter(
        arguments.input,
        jfr_only=arguments.jfr,
        columns=arguments.columns, orientation=arguments.orientation)
    converter.output(arguments.output)
except RuntimeError as e:
    print('ERROR: %s' % (str(e)), file=sys.stderr)