]> git.sommitrealweird.co.uk Git - curses-crossword.git/commitdiff
read crossword file name from args list
authorBrett Parker <iDunno@sommitrealweird.co.uk>
Thu, 9 Jul 2009 14:01:39 +0000 (15:01 +0100)
committerBrett Parker <iDunno@sommitrealweird.co.uk>
Thu, 9 Jul 2009 14:04:10 +0000 (15:04 +0100)
curses-crossword.py

index 06d944ea3d3dbd13484792d45394b23e48a32729..92f9b926394fa9ee8df623d348cd0715c4c2ff10 100644 (file)
@@ -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,26 @@ except:
     for number in range(0,10):
         superscript_numbers[str(number)] = str(number)
 
-crossworddata = codecs.open("crossword.output", "r", "utf-8").read()
+filename = None
+
+(options, args) = getopt.getopt(sys.argv[1:], "f:", "file=")
+
+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