Actually looking up data entry
This commit is contained in:
40
app.py
40
app.py
@@ -74,13 +74,17 @@ def fetch_all_projects():
|
||||
|
||||
# List projects (all pages)
|
||||
projects = list_all_projects(bearer)
|
||||
# todo, only 10 projects
|
||||
projects = projects[:10]
|
||||
|
||||
# Fetch details for each
|
||||
detailed_rows = []
|
||||
for p in projects:
|
||||
pid = (p.get("projectId") or {}).get("native")
|
||||
c = fetch_client(bearer, (p.get("clientId") or {}).get("native"))
|
||||
print("fetched client")
|
||||
cs = fetch_contacts(bearer, pid)
|
||||
print("fetched contacts")
|
||||
|
||||
if pid is None:
|
||||
continue
|
||||
@@ -89,9 +93,17 @@ def fetch_all_projects():
|
||||
except Exception as e:
|
||||
print(f"[WARN] detail fetch failed for {pid}: {e}")
|
||||
detail = {}
|
||||
from pprint import pprint
|
||||
defendant_one = next((c.get('orgContact', {}) for c in cs if "Defendant" in c.get('orgContact', {}).get('personTypes', [])), {})
|
||||
new_file_review = fetch_form(bearer, pid, "newFileReview") or {}
|
||||
dates_and_deadlines = fetch_form(bearer, pid, "datesAndDeadlines") or {}
|
||||
row = {
|
||||
"client": c.get("firstName"),
|
||||
"matter_description": p.get("projectName"),
|
||||
"defendant_1": defendant_one.get('fullName', 'Unknown'),
|
||||
"matter_open": p.get("createdDate"),
|
||||
"notice_type": new_file_review.get("noticeType", '') or '',
|
||||
"case_number": dates_and_deadlines.get('caseNumber', '') or '',
|
||||
"contacts": cs,
|
||||
"ProjectEmailAddress": p.get("projectEmailAddress"),
|
||||
"Number": p.get("number"),
|
||||
@@ -208,7 +220,9 @@ def get_filevine_bearer():
|
||||
resp = requests.post(url, data=data, headers=headers, timeout=30)
|
||||
resp.raise_for_status()
|
||||
js = resp.json()
|
||||
return js.get("access_token")
|
||||
token = js.get("access_token")
|
||||
print(f"Got bearer {token}")
|
||||
return token
|
||||
|
||||
|
||||
def list_all_projects(bearer: str):
|
||||
@@ -222,7 +236,10 @@ def list_all_projects(bearer: str):
|
||||
results = []
|
||||
last_id = None
|
||||
tries = 0
|
||||
while True:
|
||||
# TODO we probably need to sync the data with fierbase
|
||||
while len(results) < 200:
|
||||
cnt = len(results)
|
||||
print(f"list try {tries}, last_id {last_id}, count {cnt}")
|
||||
tries += 1
|
||||
url = base
|
||||
params = {}
|
||||
@@ -281,6 +298,25 @@ def fetch_contacts(bearer: str, project_id_native: int):
|
||||
return r.json().get("items")
|
||||
|
||||
|
||||
def fetch_form(bearer: str, project_id_native: int, form: str):
|
||||
try:
|
||||
url = f"https://api.filevineapp.com/fv-app/v2/Projects/{project_id_native}/Forms/{form}"
|
||||
headers = {
|
||||
"Accept": "application/json",
|
||||
"Authorization": f"Bearer {bearer}",
|
||||
"x-fv-orgid": str(FV_ORG_ID),
|
||||
"x-fv-userid": str(FV_USER_ID),
|
||||
}
|
||||
r = requests.get(url, headers=headers, timeout=30)
|
||||
r.raise_for_status()
|
||||
return r.json()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return {}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@app.route("/dashboard")
|
||||
|
||||
Reference in New Issue
Block a user