-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprovider_refactor.py
More file actions
65 lines (44 loc) · 1.74 KB
/
provider_refactor.py
File metadata and controls
65 lines (44 loc) · 1.74 KB
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
58
59
60
61
62
63
64
65
import json
import uuid
# FIRST FIX PROVIDERS
file_name = './stub_json/Providers.json'
file = open(file_name, 'r')
data = json.loads(file.read())
file.close()
providers = data['providers']
new_dict = {'providers': {}}
provider_id_to_hash_map = {}
counter = 0
for provider in providers:
uniq_id = uuid.uuid5(uuid.NAMESPACE_OID, str(provider))
new_dict['providers'][str(uniq_id)] = provider
provider['uniq_id'] = str(uniq_id)
name = provider['provider_id']
# b/c whoever designed this made the provider_id in a receipts object only have the name, not the location, so we can't know if the old data meant that this receipts was from the alberstons in King County or in Walla Walla, so I'm arbitrarily choosing the one that I loop over first to be the one that gets the receipt credit
if name not in provider_id_to_hash_map:
provider_id_to_hash_map[name] = str(uniq_id)
else:
counter += 1
print('There are {} duplicate providers in the providers table'.format(counter))
with open(file_name, 'w') as outfile:
json.dump(new_dict, outfile)
# NOW FIX CONTRIBUTIONS W/NEW PROVIDER IDS
file_name = './stub_json/Contributions.json'
file = open(file_name, 'r')
data = json.loads(file.read())
file.close()
receipts = data['contributions']
new_dict = {'contributions': []}
counter = 0
for receipt in receipts:
name = receipt['provider_id']
try:
uniq_id = provider_id_to_hash_map[name]
except:
counter += 1
uniq_id = 'INVALID PROVIDER ID'
receipt['provider_id'] = uniq_id
new_dict['contributions'].append(receipt)
print('{} receipts have provider_ids listed that do not exist in the providers table'.format(counter))
with open(file_name, 'w') as outfile:
json.dump(new_dict, outfile)