Last active
May 24, 2019 17:30
-
-
Save zacharysyoung/f6fa49a92fd6ecf58b6f5547412a2d99 to your computer and use it in GitHub Desktop.
Permutate punctuation for test GMails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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: | |
[email protected] | |
[email protected] | |
[email protected] | |
[email protected] | |
[email protected] | |
[email protected] | |
[email protected] | |
[email protected] | |
[email protected] | |
[email protected] | |
[email protected] | |
[email protected] | |
[email protected] | |
[email protected] | |
[email protected] | |
[email protected] | |
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