Skip to content

Instantly share code, notes, and snippets.

@yohayg
Created March 12, 2018 09:20
Show Gist options
  • Save yohayg/600ded7333349908603468e2211287ee to your computer and use it in GitHub Desktop.
Save yohayg/600ded7333349908603468e2211287ee to your computer and use it in GitHub Desktop.
Generates leads
#!/usr/bin/env python
# coding=utf-8
import argparse
import csv
import sys
import time
import uuid
from faker import Faker
fake = Faker()
def progress(count, total_number, status=''):
bar_len = 60
filled_len = int(round(bar_len * count / float(total_number)))
percents = round(100.0 * count / float(total_number), 1)
bar = '=' * filled_len + '-' * (bar_len - filled_len)
sys.stdout.write('[%s] %s%s ...%s\r' % (bar, percents, '%', status))
sys.stdout.flush()
parser = argparse.ArgumentParser(description='Generates leads')
parser.add_argument('leads_number', metavar='N', type=int, nargs=1,
help='The number of leads to generate')
parser.add_argument('output_file', metavar='F', type=str, nargs=1,
help='The output file')
args = parser.parse_args()
total = args.leads_number[0]
print(total)
start_time = time.time()
# your script
output_file = args.output_file[0]
print(output_file)
outfile = open(output_file, 'w+')
outfileWriter = csv.writer(outfile, delimiter=',')
header = ['Email', 'First Name', 'Last Name']
outfileWriter.writerow(header)
print('Generating ' + str(total) + ' email')
bulk_lines = []
bulk_size = 1000
for i in range(total):
first = str(fake.first_name())
last = str(fake.last_name())
email = str(fake.email())
line = [email, first, last]
# id = str(uuid.uuid4())
# line.append(id)
elapsed_time = time.time() - start_time
elapsed_time_str = str(time.strftime("%H:%M:%S", time.gmtime(elapsed_time)))
progress(i, total, status=elapsed_time_str)
bulk_lines.append(line)
if len(bulk_lines) == bulk_size:
outfileWriter.writerows(bulk_lines)
bulk_lines = []
# write the rest
if len(bulk_lines) > 0:
outfileWriter.writerows(bulk_lines)
bulk_lines = []
outfile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment