-
Notifications
You must be signed in to change notification settings - Fork 102
/
srtmread.py
34 lines (29 loc) · 997 Bytes
/
srtmread.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
import os
import sys
from pathlib import Path
import srtm
def elevationtoinflux(lat, lon, vin, displayname, ts, ifclient, dryrun, logger):
if not os.path.isfile('srtm.lck.' + str(os.getpid())):
Path('srtm.lck.' + str(os.getpid())).touch()
elevation_data = srtm.get_data()
elevation = elevation_data.get_elevation(lat, lon)
os.remove('srtm.lck.' + str(os.getpid()))
logger.debug("Elevation: " + str(elevation))
elev_json_body = [
{
"measurement": "drive_state",
"tags": {
"vin": vin,
"display_name": displayname,
},
"time": int(ts * 1000000),
"fields": {
"elevation": elevation
}
}
]
if not dryrun and elevation is not None:
ifclient.write_points(elev_json_body)
else:
print("Lockfile detected, skipping")
sys.exit()