Skip to content

Instantly share code, notes, and snippets.

@rdegges
Last active October 10, 2021 05:22
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 rdegges/421acae378d7d05e6c6be560eb1b4ff5 to your computer and use it in GitHub Desktop.
Save rdegges/421acae378d7d05e6c6be560eb1b4ff5 to your computer and use it in GitHub Desktop.
Small Python hack to purge Google Contacts of any contacts without a phone number.
# for context: https://twitter.com/rdegges/status/1447066985213292544?s=20
import csv
ORIG_FILE = 'contacts.csv'
NEW_FILE = 'contacts-clean.csv'
PHONE_NUMBER_INDEX = 41
with open(NEW_FILE, 'w', newline='\n') as wfile:
writer = csv.writer(wfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
with open(ORIG_FILE) as rfile:
reader = csv.reader(rfile, delimiter=',', quotechar='"')
for row in reader:
x = row[PHONE_NUMBER_INDEX]
if x:
writer.writerow(row)
print(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment