diff options
Diffstat (limited to 'rtfconvert.py')
-rwxr-xr-x | rtfconvert.py | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/rtfconvert.py b/rtfconvert.py index 8b61cb1..2e875f0 100755 --- a/rtfconvert.py +++ b/rtfconvert.py @@ -21,10 +21,21 @@ import sys # This is a script to take the a file in RTF format and convert it to a text file readable by Read Etexts. -def convert(file_path): +def check(file_path): rtf_file = open(file_path,"r") - out = open("book.txt", 'w') + line = rtf_file.readline() + rtf_file.close() + + if line.startswith('{\\rtf1'): + return True + else: + return False + +def convert(file_path, output_path): + + rtf_file = open(file_path,"r") + out = open(output_path, 'w') brace_count = 0 while rtf_file: @@ -78,7 +89,11 @@ def count_braces(string): if __name__ == "__main__": try: opts, args = getopt.getopt(sys.argv[1:], "") - convert(args[0]) + if check(args[0]): + print 'It is an RTF file' + convert(args[0], args[1]) + else: + print 'It is NOT an RTF file' except getopt.error, msg: print msg print "This program has no options" |