-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch_applications.py
executable file
·54 lines (50 loc) · 2.06 KB
/
fetch_applications.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
#!/usr/bin/env python3
import requests
import pandas as pd
from pprint import pprint
import json
import os
from tqdm.auto import tqdm
URL = "https://connect.pharmac.govt.nz/apptracker/s/sfsites/aura"
df = pd.concat(pd.read_csv(f) for f in ["CS_CN.csv", "Decline.csv", "OFI.csv"])
print(df)
record_ids = df.Community_URL.str.replace("/apptracker/s/application-public/", "")
print(record_ids)
for record_id in tqdm(record_ids):
resp = requests.post(
URL,
data={
"message": json.dumps(
{
"actions": [
{
"id": "108;a",
"descriptor": "apex://AppTrackerController/ACTION$getStateJson",
"callingDescriptor": "markup://c:AppTracker_List",
"params": {
"applicationId": record_id,
"expandAll": True,
},
},
{
"id": "150;a",
"descriptor": "apex://AppTrackerController/ACTION$getAppInfo",
"callingDescriptor": "markup://c:AppTracker_Info",
"params": {"appId": record_id},
},
]
}
),
"aura.context": '{"mode":"PROD","fwuid":"eUNJbjV5czdoejBvRlA5OHpDU1dPd1pMVExBQkpJSlVFU29Ba3lmcUNLWlE5LjMyMC4y","app":"siteforce:communityApp","loaded":{"APPLICATION@markup://siteforce:communityApp":"1184_AgcTXn_6dZSShHXZ2PZsug"},"dn":[],"globals":{},"uad":false}',
"aura.token": "null",
},
).json()
by_id = {}
for a in resp["actions"]:
by_id[a["id"]] = a
meta = by_id["150;a"]["returnValue"]
meta = pd.DataFrame(meta).head(1)
os.makedirs("applications", exist_ok=True)
meta.to_csv(f"applications/{record_id}_meta.csv", index=False)
df = pd.DataFrame(json.loads(by_id["108;a"]["returnValue"]))
df.to_csv(f"applications/{record_id}.csv")