from typing import Optional, Dict
import os
import requests
ACCESS_TOKEN = os.environ["WHITSON_API_TOKEN"]
CLIENT_NAME = os.environ["CLIENT_NAME"]
def get_well(
project_id: Optional[int] = None,
name: Optional[str] = None,
uwi_api: Optional[str] = None,
):
"""
Get a list of wells.
"""
base_url = f"http://{CLIENT_NAME}.whitson.com/api-external/v1/wells"
response = requests.get(
base_url,
headers={
"content-type": "application/json",
"Authorization": f"Bearer {ACCESS_TOKEN}",
},
params={"project_id": project_id, "name": name, "uwi_api": uwi_api},
)
res = response.json()
if not res:
raise Exception("no existing wells")
return res
def upload_production_to_well(well_id: int, payload: Dict[str, list]):
"""
Upload production to well.
"""
response = requests.post(
f"http://{CLIENT_NAME}.whitson.com/api-external/v1/wells/{well_id}/production_data",
headers={
"content-type": "application/json",
"Authorization": f"Bearer {ACCESS_TOKEN}",
},
json=payload,
)
if response.status_code >= 200 and response.status_code < 300:
print(f"success on well_id {well_id}")
else:
print(response.text)
if __name__ == "__main__":
well_json = get_well(
project_id=1, name="SPE-DATA-REPOSITORY-DATASET-1-WELL-1-OSPREY"
)[0]
well_id = well_json["id"]
well_name = well_json["name"]
print("uploading production to well: ", well_id, ", well name", well_name)
payload = {
"production_data": [
{
"date": "2015-01-01 00:00",
"p_wf_measured": 5050,
"p_casing": 2065,
"p_tubing": 15,
"qg_sc": 145.0,
"qw_sc": 718,
"qo_sc": 504.39,
},
{
"date": "2015-01-02 00:00",
"p_wf_measured": 5010,
"p_casing": 1990,
"p_tubing": 15,
"qg_sc": 186.0,
"qw_sc": 922,
"qo_sc": 564.76,
},
]
}
upload_production_to_well(well_id, payload)