def get_inspections(projects): if os.path.isfile(INSPECTION_JSON_FILE): os.remove(INSPECTION_JSON_FILE) output = open(INSPECTION_JSON_FILE, 'a') if os.path.isfile(INSPECTION_MASTER_FILE): os.remove(INSPECTION_MASTER_FILE) print("\n-------------------------------------" "\nInitializing get_inspection_list()") for i in range(len(projects)): job_index = projects[i]['id'] job = projects[i]['project_number'] url = "https://api.procore.com/vapid/checklist/lists/" if isinstance(projects[i]['project_number'], str) and len(projects[i]['project_number']) == 6: if projects[i]['company']['id'] == CONSTRUCTION_ID: querystring = {"company_id": CONSTRUCTION_ID, "project_id": job_index} headers = {'Authorization': "Bearer " + refresh_construction_token()} r = make_api_call(url, querystring, headers) print('[0]' + str(r.status_code) + ': ' + r.headers['content-type'] + ' | ' + str(r.headers['content-length'])) response = json.loads(r.text) print(job + ": " + str(len(response)) + " inspections found") for i in range(len(response)): for ii in range(len(response[i]['lists'])): showUrl = url + str(response[i]['lists'][ii]['id']) rr = make_api_call(showUrl, querystring, headers) print('[1]' + str(rr.status_code) + ': ' + rr.headers['content-type']) data = json.loads(rr.text) print(job + ": Template " + str(i) + " of " + str(len(response))) print(job + ": Inspection " + str(ii) + " of " + str(len(response[i]['lists']))) prettyData = json.dumps(data, sort_keys=True, indent=4) output.write(prettyData) write_row(data, job_index) else: querystring = {"company_id": HEALTHCARE_ID, "project_id": job_index} headers = {'Authorization': "Bearer " + refresh_healthcare_token()} r = make_api_call(url, querystring, headers) print('[2]' + str(r.status_code) + ': ' + r.headers['content-type']) response = json.loads(r.text) print(job + ": " + str(len(response)) + " inspections found") for i in range(len(response)): for ii in range(len(response[i]['lists'])): showUrl = url + str(response[i]['lists'][ii]['id']) rr = make_api_call(showUrl, querystring, headers) print('[3]' + str(rr.status_code) + ': ' + rr.headers['content-type'] + ' | ' + str( rr.headers['content-length'])) data = json.loads(rr.text) print(job + ": Template " + str(i) + " of " + str(len(response))) print(job + ": Inspection " + str(ii) + " of " + str(len(response[i]['lists']))) prettyData = json.dumps(data, sort_keys=True, indent=4) output.write(prettyData) write_row(data, job_index) else: continue
def get_rfis(projects): if os.path.isfile(RFI_JSON_FILE): os.remove(RFI_JSON_FILE) output = open(RFI_JSON_FILE, 'a') if os.path.isfile(RFI_MASTER_FILE): os.remove(RFI_MASTER_FILE) print("\n-------------------------------------" "\nInitializing get_rfis()") for i in range(len(projects)): job_index = projects[i]['id'] job = projects[i]['project_number'] url = "https://api.procore.com/vapid/projects/" + str( job_index) + "/rfis" if isinstance(projects[i]['project_number'], str) and len( projects[i]['project_number']) == 6: if projects[i]['company']['id'] == CONSTRUCTION_ID: querystring = {"company_id": CONSTRUCTION_ID} headers = { 'Authorization': "Bearer " + refresh_construction_token() } response = json.loads( make_api_call(url, querystring, headers).text) print(job + ": " + str(len(response)) + " rfis found") for i in range(len(response)): showUrl = url + "/" + str(response[i]['id']) data = json.loads( make_api_call(showUrl, querystring, headers).text) print(job + ": Rfi " + str(i) + " of " + str(len(response))) prettyData = json.dumps(data, sort_keys=True, indent=4) output.write(prettyData) write_row(data, job_index) else: querystring = {"company_id": HEALTHCARE_ID} headers = { 'Authorization': "Bearer " + refresh_healthcare_token() } response = json.loads( make_api_call(url, querystring, headers).text) print(job + ": " + str(len(response)) + " rfis found") for i in range(len(response)): showUrl = url + "/" + str(response[i]['id']) data = json.loads( make_api_call(showUrl, querystring, headers).text) print(job + ": Rfi " + str(i) + " of " + str(len(response))) prettyData = json.dumps(data, sort_keys=True, indent=4) output.write(prettyData) write_row(data, job_index) else: continue
def show_projects(): print("Initializing show_projects()...") url = "https://api.procore.com/vapid/projects" querystring = {"company_id": CONSTRUCTION_ID} headers = {'Authorization': "Bearer " + refresh_construction_token()} print("Pulling construction jobs") data = json.loads(make_api_call(url, querystring, headers).text) projects = data print(str(len(data)) + " jobs found") querystring = {"company_id": HEALTHCARE_ID} headers = {'Authorization': "Bearer " + refresh_healthcare_token()} print("Pulling healthcare jobs") data = json.loads(make_api_call(url, querystring, headers).text) print(str(len(data)) + " jobs found") projects += data return projects