-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrubba.py
57 lines (52 loc) · 1.63 KB
/
scrubba.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Necessary Imports
import requests
import json
from pprint import pprint
# URL to fetch the data
url = "https://raw.githubusercontent.com/amcypher/PII-Scrubber-and-Sample-Data/main/pii-json.json"
# If you need to auth
# headers = {"Content-Type": "application/json", "X-Auth-Key": key, "X-Auth-Email": email}
# Method to pull data from the API
def pull_data(url):
# Set our headers for the HTTP Request
headers = {"Content-Type": "application/json"}
# Try catch to handle failed HTTP Requests
try:
response = requests.get(url, headers=headers)
# Return the response if HTTP 200
if response.status_code == 200:
return response.json()
# Non 200 Response
else:
print(f'Status Code: {response.status_code}')
return False
except Exception as e:
# Exception occurred
print(f"API Fetch Failed: {e}")
return False
def scrubba(data):
# Removing the PII that we know exists in these Key Value Pairs
# Object references passed to this function
try:
data['pii_instances']['ssn'] = "xxx-xx-xxxx"
data['pii_instances']['date_of_birth'] = 'xxxx/xx/xx'
except KeyError as e:
print(f"KeyError: {e}")
# Main
def main():
# Get the data
my_results = pull_data(url)
# Check the outcome
if my_results:
# Scrub the data
scrubba(my_results)
# Print the keys
pprint(my_results.keys())
# Print the scrubbed version
pprint(my_results)
else:
# Something went wrong
print("Exiting Program")
exit()
if __name__ == "__main__":
main()