Created
March 29, 2020 09:22
-
-
Save cheriimoya/d05678f86e177c48a38605a62af281c1 to your computer and use it in GitHub Desktop.
contact_filter.py <contacts.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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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