Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import sys
  4.  
  5. query_file = sys.argv[1]
  6. csv_file = query_file + '.csv'
  7.  
  8. def main():
  9. with open(csv_file, 'w') as csv:
  10. with open(query_file, 'r') as qf:
  11. for line in nonblank_lines(qf):
  12. if 'INSERT' in line:
  13. parens = 0
  14. for char in line:
  15. if parens >= 1 and not(char == ')'):
  16. csv.write(char)
  17. if char == '(':
  18. parens += 1
  19. if char == ')':
  20. parens -= 1
  21. if char == ')' and parens == 0:
  22. csv.write('\n')
  23.  
  24. def nonblank_lines(qf):
  25. for l in qf:
  26. line = l.rstrip()
  27. if line:
  28. yield line
  29.  
  30.  
  31. if __name__ == "__main__":
  32. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement