Created
January 18, 2017 09:01
-
-
Save sicking/fd38436a56f5363012d78fa8645cb8fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
import sys, re | |
checkedVersion = False | |
ignoredHeaders = False | |
with open(sys.argv[1], 'rU') as csvfile: | |
for row in csvfile: | |
if not checkedVersion: | |
checkedVersion = True | |
attrs = re.split('\s*;\s*', row); | |
if attrs[1] != "Export format 1.1" or \ | |
attrs[0] != "# Generated by Password Exporter": | |
sys.exit("Unknown format: " + row) | |
continue | |
if not ignoredHeaders: | |
ignoredHeaders = True | |
continue | |
fields = row[1:-1].split('","')[:3] | |
if not (fields[0].startswith('http://') or fields[0].startswith('https://')): | |
continue | |
fields = map(lambda str: re.sub("%(..)", lambda x: chr(int(x.group(1), 16)), str), fields) | |
fields[0:0] = [re.sub("^https?://(www\.|m\.|mobile\.)?", "", fields[0])] | |
print ','.join(map(lambda str: '"' + str.replace('"', '""') + '"', fields)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment