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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275 | import http.client
import json
import os
import requests
CLIENT_NAME = **your client name**
def get_fields(access_token: str):
base_url = f"https://{CLIENT_NAME}.whitson.com/api-external/v1/"
response = requests.get(
base_url + "fields",
headers={
"content-type": "application/json",
"Authorization": f"Bearer {access_token}",
},
)
res = response.json()
if not res:
raise Exception("no existing fields")
return res
def get_wells(
access_token: str,
project_id: int | None = None,
name: str | None = None,
uwi_api: str | None = 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 get_projects(
access_token: str,
field_id: int | None = None,
):
"""
Get a list of fields.
"""
base_url = (
f"http://{CLIENT_NAME}.whitson.com/api-external/v1/fields/{field_id}/projects"
)
response = requests.get(
base_url,
headers={
"content-type": "application/json",
"Authorization": f"Bearer {access_token}",
},
)
res = response.json()
if not res:
raise Exception("no existing wells")
return res
def create_well(access_token: str, payload: dict) -> requests.Response:
"""
upload well information to create a well in the database
"""
base_url = f"http://{CLIENT_NAME}.whitson.com/api-external/v1/wells"
response = requests.post(
base_url,
headers={
"content-type": "application/json",
"Authorization": f"Bearer {access_token}",
},
json=payload,
)
if response.status_code >= 200 and response.status_code < 300:
print(f"successfully created well {payload['name']}")
else:
print(response.text)
return response
def create_project(access_token: str, field_id, payload: dict) -> requests.Response:
"""
upload well information to create a well in the database
"""
base_url = (
f"http://{CLIENT_NAME}.whitson.com/api-external/v1/fields/{field_id}/projects"
)
response = requests.post(
base_url,
headers={
"content-type": "application/json",
"Authorization": f"Bearer {access_token}",
},
json=payload,
)
if response.status_code >= 200 and response.status_code < 300:
print(f"successfully created project {payload['name']}")
else:
print(response.text)
return response
def upload_production_to_well(
access_token: str, well_id: int, payload: list[dict]
) -> requests.Response:
"""
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"successfully updated production data on well {well_id}")
else:
print(response.text)
return response
def bulk_upload_production_to_well(
access_token: str, payload: list[dict]
) -> requests.Response:
"""
Upload production to well.
"""
response = requests.post(
f"http://{CLIENT_NAME}.whitson.com/api-external/v1/wells/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("success")
else:
print(response.text)
return response
def get_production(
access_token: str,
well_id: int,
) -> requests.Response:
"""
Get a list of wells.
"""
response = requests.get(
f"http://{CLIENT_NAME}.whitson.com/api-external/v1/wells/{well_id}/production_data",
headers={
"content-type": "application/json",
"Authorization": f"Bearer {access_token}",
},
)
res = response.json()
if not res:
raise Exception("no existing wells")
return res
def edit_input_quick(
access_token: str, well_id: int, payload: dict
) -> requests.Response:
"""
Edit the input quick (PVT) property of a well.
"""
response = requests.put(
f"http://{CLIENT_NAME}.whitson.com/api-external/v1/wells/{well_id}/input_quick",
headers={
"content-type": "application/json",
"Authorization": f"Bearer {access_token}",
},
json=payload,
)
if response.status_code >= 200 and response.status_code < 300:
print(f"successfully edited input quick for well {well_id}")
else:
print(response.text)
return response
def upload_well_data_to_well(
access_token: str, well_id: int, payload: list[dict]
) -> requests.Response:
"""
Upload a well data to a well.
"""
base_url = f"http://{CLIENT_NAME}.whitson.com/api-external/v1/wells/{well_id}/bhp_input/well_data"
response = requests.post(
base_url,
headers={
"content-type": "application/json",
"Authorization": f"Bearer {access_token}",
},
json=payload,
)
if response.status_code >= 200 and response.status_code < 300:
print(f"successfully updated well_data to well {well_id}")
else:
print(response.text)
return response
def edit_well_deviation_data(
access_token: str, well_id: int, payload: list[dict]
) -> requests.Response:
"""
Edit well deviation data of a well in the database.
"""
base_url = f"http://{CLIENT_NAME}.whitson.com/api-external/v1/wells/{well_id}/bhp_input/well_deviation_survey"
response = requests.put(
base_url,
headers={
"content-type": "application/json",
"Authorization": f"Bearer {access_token}",
},
json=payload,
)
if response.status_code >= 200 and response.status_code < 300:
print(f"changed well deivation survey on well_id {well_id}")
else:
print(response.text)
return response
def run_composition_calc(access_token: str, well_id: int) -> requests.Response:
"""
Run composition calculation on well.
"""
response = requests.get(
f"http://{CLIENT_NAME}.whitson.com/api-external/v1/wells/{well_id}/run_composition_calc",
headers={
"content-type": "application/json",
"Authorization": f"Bearer {access_token}",
},
)
if response.status_code >= 200 and response.status_code < 300:
print(f"success on running composition calc on well {well_id}")
else:
print(response.text)
return response
def run_bhp_calc(access_token: str, well_id: dict) -> requests.Response:
"""
Run bhp calculation on the well specified by the provided well_id
"""
base_url = f"http://{CLIENT_NAME}.whitson.com/api-external/v1/wells/{well_id}/run_bhp_calculation"
response = requests.get(
base_url,
headers={
"content-type": "application/json",
"Authorization": f"Bearer {access_token}",
},
)
if response.status_code == 202:
print(f"successfully ran bhp calc on {well_id}")
else:
print(response.text)
return response
|