Created
May 19, 2016 15:51
-
-
Save cpulvermacher/daef7e181e9efc537df9eda21cdea2b6 to your computer and use it in GitHub Desktop.
Convert the .adr contact format (names and email only) of the Opera mail client into gmail-compatible CSV
This file contains hidden or 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
import sys | |
if len(sys.argv) != 3: | |
print ("Usage: " + sys.argv[0] + " INPUT.ADR OUTPUT.CSV\n") | |
print ("Convert the .adr contact format (names and email only) of the Opera mail client into gmail-compatible CSV.") | |
sys.exit(1) | |
adrfile = open(sys.argv[1], 'r') | |
csvfile = open(sys.argv[2], 'w+') | |
header = 'Name,E-mail 1 - Value' + '\n' | |
csvfile.write(header) | |
def write_entry(name, mail): | |
line = '"' + name + '",' + mail + '\n' | |
csvfile.write(line) | |
current_name = None | |
for line in adrfile: | |
line = line.strip() | |
if line.startswith('NAME='): | |
current_name = line[len('name='):] | |
elif line.startswith('MAIL='): | |
mail = line[len('MAIL='):] | |
write_entry(current_name, mail) | |
current_name = None | |
adrfile.close() | |
csvfile.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment