Guest User

Untitled

a guest
Nov 19th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. import sys
  2. import re
  3.  
  4. def extract(source_file, destination_file, encoding="utf-8"):
  5. source = open(source_file, mode='r', encoding=encoding)
  6. with open(destination_file, mode='w') as destination:
  7. while True:
  8. line = source.readline()
  9. if line == "":
  10. break
  11. if str.startswith(line, "Dialogue: "):
  12. destination.write(re.sub("{.*}", "", line.split(",")[9]))
  13.  
  14. def main():
  15. if(str.endswith(sys.argv[0], "extractor.py")):
  16. sys.argv.remove(sys.argv[0])
  17.  
  18. arglen = len(sys.argv)
  19. if arglen == 2:
  20. extract(sys.argv[0], sys.argv[1])
  21. elif arglen == 3:
  22. extract(sys.argv[0], sys.argv[1], sys.argv[2])
  23. elif arglen == 1 and (sys.argv[0] == "-h" or sys.argv[0] == "--help"):
  24. print("Usage: extractor <source file> <output file> [encoding]")
  25. else:
  26. print("Malformed input. Type 'extractor -h' for the expected form of input.")
  27.  
  28. main()
Add Comment
Please, Sign In to add comment