Skip to content

Instantly share code, notes, and snippets.

@Animeshz
Last active May 27, 2024 04:33
Show Gist options
  • Save Animeshz/1baf34d7afd6d7db9acce393497b25bf to your computer and use it in GitHub Desktop.
Save Animeshz/1baf34d7afd6d7db9acce393497b25bf to your computer and use it in GitHub Desktop.
IIITL Contact Extract (Unofficial WhatsApp Group)
import csv
import difflib
import io
import re
import requests
SHEET_URL = 'https://docs.google.com/spreadsheets/d/1PIVUewR8OE9LHSoEvpH6jEoaDvd3TpH2t3ryZwptxJs/edit#gid=561315341'
BRANCHES = ['CSAI', 'CSB', 'CS', 'IT']
if __name__ == '__main__':
reader = csv.DictReader(io.StringIO(requests.get(SHEET_URL.replace('/edit#gid=', '/export?format=csv&gid=')).text))
for row in reader:
name = row['Name'].strip().title()
number = row['Whatsapp Number'].strip().lstrip('0')
email = row['Email address'].strip()
allotted_branch = re.sub('AND|\+', ' ', row['Allotted Branch'].strip().upper()).rstrip('E')
if not re.match('\+?[-\d\s]+', number):
continue
first_name, _, last_name = name.rpartition(' ')
if '+' not in number:
number = '0' + number
if ' ' in allotted_branch:
allotted_branch = ''.join([word[0] for word in allotted_branch.split()])
try:
allotted_branch = difflib.get_close_matches(allotted_branch, BRANCHES)[0]
except:
continue
print('BEGIN:VCARD')
print('VERSION:2.1')
print(f'N:(IIITL|{allotted_branch});{first_name};{last_name};;')
print(f'FN:{name} (IIITL|{allotted_branch})')
print(f'TEL;CELL;PREF:{number}')
print(f'EMAIL;HOME:{email}')
print('END:VCARD')
@Animeshz
Copy link
Author

Usage: Save in .vcf file and import into contacts app.

python3 contact-extract.py > iiitl-freshers.vcf

@Animeshz
Copy link
Author

Can use termux in android if do not have laptop/pc to run python.

@Doomlol
Copy link

Doomlol commented Nov 23, 2021

to export the python file

wget https://gist.githubusercontent.com/Animeshz/1baf34d7afd6d7db9acce393497b25bf/raw/851cb6d1e82bc5f2fcc5530190f33a5d1fed05ca/contact-extract.py

@Animeshz
Copy link
Author

Animeshz commented Dec 7, 2021

Or just (without downloading python script, direct export).

curl -L https://gist.github.com/Animeshz/1baf34d7afd6d7db9acce393497b25bf/raw | python3 > iiitl-freshers.vcf

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