Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. start = "SUMMARY BY SITE"
  4. filepath = '/Users/shaunstone/Downloads/FILE.txt'
  5. out_file = open("output.csv", "w+")
  6. started = 0
  7. with open(filepath) as fp:
  8. line = fp.readline()
  9. cnt = 1
  10. while line:
  11. line = fp.readline()
  12. if line.startswith(start):
  13. started = 1
  14. if started == 1:
  15. if (line.startswith("----- ")):
  16. started = 2
  17. continue
  18. if started == 2:
  19. if not line.strip() or line == "" or line.startswith("--"):
  20. line = False
  21. else:
  22. out_file.write(' '.join(line.split()).replace(' ', ','))
  23. out_file.write('\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement