from datetime import datetime
import os
import json
import requests
import pandas as pd
import numpy as np
from combocurve_api_v1 import ServiceAccount , ComboCurveAuth, pagination
def auth_session():
fileName = "API Service Key2.json"
filePath = r"\\GRN-AZ-APPS-01\Petra"
if not os.path.exists(filePath):
print("Network drive not accessible ")
service_file = os.path.join(filePath,fileName)
if not os.path.exists(service_file):
print("Service API file not accessible ")
service_account = ServiceAccount.from_file(service_file)
api_key = "**####REMOVED BY ADMIN###**"
combo_curve_auth = ComboCurveAuth(service_account, api_key)
auth_headers = combo_curve_auth.get_auth_headers()
return auth_headers
auth_headers = auth_session()
projectId = ‘636a654f650fb80012bafc97’
url_endpoint = “https://api.combocurve.com/v1/projects/636a654f650fb80012bafc97/company-wells?take=1000”
complete_df = pd.DataFrame()
get_next_page = True
page_num = 1
while get_next_page:
response = requests.get(url_endpoint, headers = auth_headers)
if response.status_code != 200:
raise Exception (f"Error getting data table: {response.status_code}, {response.text}")
else:
#print({response.status_code})#, {response.text})
print("getting page: ", page_num)
data = response.text
url_endpoint = pagination.get_next_page_url(response.headers)
page_num = page_num +1
get_next_page = url_endpoint is not None
data_dict = json.loads(data)
df = pd.json_normalize(data_dict)
complete_df = pd.concat([complete_df,df],ignore_index = True)
print (complete_df.shape)
cc_header_DF = complete_df.fillna(np.nan)#where(pd.notna(complete_df), None))
well_list = cc_header_DF[‘id’]
#print (complete_df.shape)
# Create a dictionary of fill values based on data types
#fill_values = {col: 0 if complete_df[col].dtype.kind in ‘biufc’ else ‘’ for col in complete_df.columns}
# Fill NaN values using the dictionary
#complete_df = complete_df.fillna(fill_values)
#cc_header_table = complete_df #.fillna(where(pd.notna(df), None)