Skip to content

Instantly share code, notes, and snippets.

@zacharysyoung
Last active May 24, 2019 17:30
Show Gist options
  • Save zacharysyoung/f6fa49a92fd6ecf58b6f5547412a2d99 to your computer and use it in GitHub Desktop.
Save zacharysyoung/f6fa49a92fd6ecf58b6f5547412a2d99 to your computer and use it in GitHub Desktop.
Permutate punctuation for test GMails
#!/usr/bin/env python
import sys
"""
Got the idea from https://learn.lytics.com/understanding/product-docs/lytics-javascript-tag/testing-and-verification#testing-audiences
Given an input of "test", makes:
t.e.s.t.@gmail.com
t.e.s.t@gmail.com
t.e.st.@gmail.com
t.e.st@gmail.com
t.es.t.@gmail.com
t.es.t@gmail.com
t.est.@gmail.com
t.est@gmail.com
te.s.t.@gmail.com
te.s.t@gmail.com
te.st.@gmail.com
te.st@gmail.com
tes.t.@gmail.com
tes.t@gmail.com
test.@gmail.com
test@gmail.com
This list gets exponentially big--7 letters in the name = 128 versions of the
name--so make sure to redirect to a file (I picked a CSV extension so
the list can be loaded and tracked in Excel):
python make_test_gmails.py test > test_gmails.csv
"""
def binary_puncs(s, _len, puncs):
if len(s) == _len:
puncs.append(s)
return puncs
puncs = binary_puncs(s + '.', _len, puncs)
# Encode a space (' ') as a place-holder for not-punctuated, e.g.,
# ['.. .', '. . ', ' . .']
puncs = binary_puncs(s + ' ', _len, puncs)
return puncs
def make_test_names(name):
punctuation_sets = binary_puncs('', len(name), [])
letter_fields = [c for c in name]
punctuated_names = []
for punc_set in punctuation_sets:
punc_fields = [c for c in punc_set]
component_fields = zip(letter_fields, punc_fields)
punctuated_name = ''.join(
[''.join(cf).strip() for cf in component_fields])
punctuated_names.append(punctuated_name)
return punctuated_names
def make_test_gmails(punctuated_names):
gmails = []
for pn in punctuated_names:
gmails.append('@'.join([pn, 'gmail.com']))
return gmails
if __name__ == '__main__':
name = sys.argv[1]
punctuated_names = make_test_names(name)
gmails = make_test_gmails(punctuated_names)
for gmail in gmails:
print(gmail)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment