Skip to content

Instantly share code, notes, and snippets.

@cheriimoya
Created March 29, 2020 09:22
Show Gist options
  • Save cheriimoya/d05678f86e177c48a38605a62af281c1 to your computer and use it in GitHub Desktop.
Save cheriimoya/d05678f86e177c48a38605a62af281c1 to your computer and use it in GitHub Desktop.
contact_filter.py <contacts.csv>
from sys import argv
import vobject
with open(argv[1]) as f:
contacts_object = vobject.readComponents(f)
contacts = []
try:
while True:
c = next(contacts_object)
if c.validate():
contacts.append(c)
except StopIteration:
pass
for index, c in enumerate(contacts):
try:
del c.photo
except:
pass
with open('output.vcf', 'w') as f:
for c in contacts:
try:
c.tel
f.write(c.serialize())
except AttributeError:
pass
@cheriimoya
Copy link
Author

https://pypi.org/project/vobject/ needed

will read all contacts from the provided file, validate them and remove the contact picture.
i used it to sanitize all my contacts exported from android for the import into nextcloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment