diff options
author | James Simmons <jim@simmons.olpc> | 2009-09-06 22:17:00 (GMT) |
---|---|---|
committer | James Simmons <jim@simmons.olpc> | 2009-09-06 22:17:00 (GMT) |
commit | 73e671a6ce86308d61b95264953aa79d63d30cdc (patch) | |
tree | fbe0a938db9609d4771aec3733540c13bf727907 /rtfconvert.py | |
parent | 95a1ab0f394bb41b3e3aa9eeb9b4dd02ce78ba0d (diff) |
modified: ReadEtextsActivity.pyv17
modified: rtfconvert.py
Support conversion of RTF documents.
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" |