Created
March 25, 2020 00:36
-
-
Save mrdougwright/4c6d8c5459c3e405f358eb004fd842cb to your computer and use it in GitHub Desktop.
versus scrubber
This file contains 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
def scrub(data): | |
if type(data) is list: | |
return scrub_list(data) | |
elif type(data) is dict: | |
return scrub_obj(data) | |
else: | |
return data | |
def scrub_list(data): | |
new_list = [] | |
for x in data: | |
new_list.append(scrub(x)) | |
return new_list | |
def scrub_obj(data): | |
obj = {} | |
for key in data: | |
if is_concealable(key): | |
obj[key] = conceal(data[key]) | |
else: | |
obj[key] = scrub(data[key]) | |
return obj | |
def conceal(arg): | |
if "@" in arg: | |
return conceal_email(arg) | |
return "*****" | |
def conceal_email(email): | |
[name, domain] = email.split("@") | |
return "*****@" + domain | |
def is_concealable(key): | |
if key == "name": | |
return True | |
if key == "email": | |
return True | |
if key == "username": | |
return True | |
if key == "password": | |
return True | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment