Skip to content

Instantly share code, notes, and snippets.

@ikoniaris
Created April 12, 2018 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikoniaris/470a5836360539906db6b712d2d6845d to your computer and use it in GitHub Desktop.
Save ikoniaris/470a5836360539906db6b712d2d6845d to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# Converts LinkedIn connections exported as CSV to VCF (vCards), which can then be
# imported into contact managers like Monica: https://github.com/monicahq/monica
#
# LinkedIn instructions: https://www.linkedin.com/help/linkedin/answer/66844/exporting-connections-from-linkedin?lang=en
# vCard 3.0 information: https://en.wikipedia.org/wiki/VCard#vCard_3.0
import csv
import sys
def convert(file):
with open(file, newline='', encoding='utf-8', mode='r') as input_file:
reader = csv.reader(input_file)
next(reader, None) # skip the headers
with open('output.vcf', encoding='utf-8', mode='w') as output_file:
for row in reader:
print('BEGIN:VCARD', file=output_file)
print('VERSION:3.0', file=output_file)
print('FN:' + row[0] + ' ' + row[1], file=output_file)
print('N:' + row[1] + ';' + row[0] + ';', file=output_file)
print('EMAIL;TYPE=INTERNET:' + row[2], file=output_file)
print('ORG:' + row[3], file=output_file)
print('TITLE:' + row[4], file=output_file)
print('END:VCARD', file=output_file)
def main(args):
if len(args) != 2:
print("Usage:")
print(args[0] + " filename")
return
convert(args[1])
if __name__ == '__main__':
main(sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment