-
Notifications
You must be signed in to change notification settings - Fork 0
/
post_functions.py
90 lines (71 loc) · 2.74 KB
/
post_functions.py
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
import requests
import json
from get_functions import *
base_url = 'https://kghub.caiag.kg/api/'
org_uuid = "421f9617-3714-4700-b063-6c4c6d6889be"
bearer_token = 'testing'
json_headers = {
'Authorization': f'Bearer {bearer_token}',
'Content-Type': 'application/json' # Specify that the data is in JSON format
}
def create_location( organisation_uuid, location_name, location_code, coordinates):
"""
Creates a location on the server using the specified data.
Parameters:
- organisation_uuid (str): The UUID of the organization.
- location_name (str): The name of the location.
- access_modifier (int): Access level for the location.
- location_code (str): Unique code for the location.
- coordinates (tuple): A tuple of (longitude, latitude, elevation).
Returns:
- dict: JSON response from the server.
"""
location_url = base_url+ "locations/"
# Data payload for the POST request
data = {
'name': location_name,
'code': location_code,
'organisation': organisation_uuid,
'geometry': {
"type": "Point",
"coordinates": list(coordinates)
},
'extra_met': True
}
# Send POST request to create location
response = requests.post(url=location_url, data=json.dumps(data), headers=json_headers)
# Return JSON response
return response.json()
post = create_location("421f9617-3714-4700-b063-6c4c6d6889be",
'bishkek precipitation', "bishkek_precip",
(74.590958, 42.871773, 0.0))
def create_timeseries(name, code, location_uuid, observation_code, base_url, json_headers):
"""
Function to create a timeseries entry.
Args:
name (str): Name for the location.
code (str): Unique code for the location (letters and numbers).
location_uuid (str): UUID of the location.
observation_code (int): Code representing the type of observation.
timeseries_url (str): URL endpoint for posting the timeseries data.
json_headers (dict): Headers to include with the request (e.g., authentication and content type).
Returns:
dict: JSON response from the API.
"""
timeseries_url = base_url+ "timeseries/"
data = {
'name': name,
'code': code,
'location': location_uuid,
'value_type': 1,
'observation_type': observation_code,
'timeseries_type': None
}
response = requests.post(
url=timeseries_url,
data=json.dumps(data),
headers=json_headers
)
return response.json()
loc_uuid = get_locations_single(base_url,org_uuid,'bishkek_precip' )['uuid'][0]
ts = create_timeseries('precipitation data gpm','precip_gpm', loc_uuid, 1 , base_url, json_headers)