Skip to content

Instantly share code, notes, and snippets.

@krisrak
Last active April 23, 2017 20:54
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save krisrak/cba642f8000168b829b05e7bcea7c161 to your computer and use it in GitHub Desktop.
Python script to find emails in bio and update followers csv exported from picodash.com
#!/usr/bin/python
import sys
import csv
import re
try:
filename = sys.argv[1]
except:
print "\nERROR: Please specify filename\n"
print "Usage:"
print " $ picodash_export_bioemail.py data.csv\n"
print "- First param should be the csv file path\n"
sys.exit(0)
new_data=[]
# open csv file to find emails
with open(filename, 'r') as csvfile:
csv_reader = csv.reader(csvfile)
# iterate on all rows in csv
for row_index,row in enumerate(csv_reader):
# find the index of bio column
if row_index == 0:
BIO_COL_NUM = None
for col_index,col in enumerate(row):
if col == "bio":
BIO_COL_NUM = col_index
row.append("email")
new_data.append(row)
continue
# check if bio exists and find emails in rows
bio = row[BIO_COL_NUM]
if bio != '':
emails = re.findall(r'[\w\.-]+@[\w\.-]+', bio)
row.append(",".join(emails))
new_data.append(row)
if emails:
print "Found email: "+(','.join(emails))
else:
row.append("")
new_data.append(row)
with open(filename, 'w') as csvfile:
csv_writer = csv.writer(csvfile, lineterminator='\n')
csv_writer.writerows(new_data)
print "Updated CSV with location column: " + filename
@krisrak
Copy link
Author

krisrak commented Apr 23, 2017

This is a Python script to add emails column (from bio description) in csv for followers exported from picodash.com

You have to specify the csv_filename. The script will add a new column "email" and add emails found in the bio description

Usage:
/usr/bin/python picodash_export_bioemail.py <csv_filename>

Example:
/usr/bin/python picodash_export_bioemail.py data.csv

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