-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcam_sensors.py
More file actions
31 lines (27 loc) · 1.16 KB
/
cam_sensors.py
File metadata and controls
31 lines (27 loc) · 1.16 KB
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
#sensor name to retrieve
#log file start and stop time to match to sensors you are retrieving
#to me it looks like kat_store is running on a SAST timezone
def sensor_data_pvsn(sensor, timestart, timestop):
import requests
sensors_url = 'http://portal.mkat.karoo.kat.ac.za/katstore/api/query'
sample_params = {'sensor':sensor,
'start_time':timestart.strftime('%s'),
'end_time': timestop.strftime('%s'),
'include_value_time': True}
#Debug
#print(sample_params)
try:
resp = requests.get(sensors_url, sample_params)
except Exception as exc:
print('Something failed: {}'.format(exc))
if resp.status_code == 200:
sample_results = resp.json()
#Debug
#print(resp.json())
timestampv=[sample['value_time'] for sample in sample_results['data']]
timestamps=[sample['sample_time'] for sample in sample_results['data']]
samples=[sample['value'] for sample in sample_results['data']]
else:
print("Request returned with a status code {}".format(resp.status_code))
print(resp)
return(timestampv,timestamps,samples)