Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import zipfile
- import sys
- import io
- import os
- def fix(filename):
- correctlines = []
- with open(filename, 'r') as fields:
- lines = list(fields);
- for line in lines:
- parts = line.split(',')
- if len(parts) > 4:
- parts = parts[:3] + ['"' +
- ','.join(parts[3:]).replace('\n', '').replace('"', '""') +
- '"\n']
- correctlines += ','.join(parts)
- with open(filename, 'w') as fields:
- fields.writelines(correctlines)
- filelist = [
- 'fields.csv',
- 'methods.csv',
- ]
- with zipfile.ZipFile(sys.argv[1], 'r') as archive:
- archive.extractall()
- for filename in filelist:
- fix(filename)
- with zipfile.ZipFile(sys.argv[1].replace('.zip', '-fixed.zip'), 'w') as fixed:
- for filename in filelist:
- fixed.write(filename)
- os.remove(filename)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement