Skip to content

Instantly share code, notes, and snippets.

@mrdougwright
Created March 25, 2020 00:36
Show Gist options
  • Save mrdougwright/4c6d8c5459c3e405f358eb004fd842cb to your computer and use it in GitHub Desktop.
Save mrdougwright/4c6d8c5459c3e405f358eb004fd842cb to your computer and use it in GitHub Desktop.
versus scrubber
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