X-Git-Url: https://git.sommitrealweird.co.uk/curses-crossword.git/blobdiff_plain/6d8b08d493f552b54ab4452135d8c3e581b8eebe..95013783a7b2dcf4f9f2c9a13c2e7d1b0e319b59:/curses-crossword.py diff --git a/curses-crossword.py b/curses-crossword.py index 06d944e..19ee754 100644 --- a/curses-crossword.py +++ b/curses-crossword.py @@ -4,6 +4,9 @@ import curses import curses.ascii import locale import codecs +import getopt +import os +import sys locale.setlocale(locale.LC_ALL, '') code = locale.getpreferredencoding() @@ -27,7 +30,30 @@ except: for number in range(0,10): superscript_numbers[str(number)] = str(number) -crossworddata = codecs.open("crossword.output", "r", "utf-8").read() +filename = None + +try: + (options, args) = getopt.getopt(sys.argv[1:], "f:", "file=") +except getopt.GetoptError, err: + print str(err) + sys.exit(2) + +for option in options: + if option[0] == "-f" or option[0] == "--file": + filename = option[1] + +if not filename and len(args) > 0: + filename = args[0] + +if not filename: + sys.stderr.write("No crossword file specified, exiting.\n") + sys.exit(0) + +if os.path.exists(filename) and os.path.isfile(filename): + crossworddata = codecs.open(filename, "r", "utf-8").read() +else: + sys.stderr.write("Couldn't open file %s\n" %(filename)) + sys.exit(0) def parsecrossword(crossworddata): ingrid = False