forked from eodms-sgdot/eodms-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_site_record.py
More file actions
71 lines (58 loc) · 2.19 KB
/
create_site_record.py
File metadata and controls
71 lines (58 loc) · 2.19 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
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
import argparse
import configparser
import json
import requests
def main():
args = parse_args()
config = get_config_params("/home/ec2-user/eodms-cli/config.ini")
# Check if the target exists
response = requests.get(f'http://10.70.137.99/targets/{args.label}')
# if the target doesnt exist post it
if response.content == b'{"detail":"Target not found"}':
f = open(f'AOIs/{args.label}.json')
data = json.load(f)
coordinates = data['features'][0]['geometry']['coordinates'][0]
# Remove height value in coordinate list
for coord in coordinates:
coord.pop()
json_content={
"label": args.label,
"name_en": args.name_en,
"name_fr": args.name_fr,
"geometry": {
"type": "Polygon",
"coordinates": [coordinates]
}
}
response = requests.post('http://10.70.137.99/targets',
json=json_content)
return response.content
def get_config_params(args):
"""
Parse Input/Output columns from supplied *.ini file
"""
configParseObj = configparser.ConfigParser()
configParseObj.read(args)
return configParseObj
def parse_args():
parser = argparse.ArgumentParser(description=(""))
parser.add_argument("--site",
type=str,
help='Volcanic Site Name',
required=True)
parser.add_argument("--label",
type=str,
help='Name of site label, same format as AOI kml',
required=True)
parser.add_argument("--name_en",
type=str,
help='Volcano Name in english',
required=True)
parser.add_argument("--name_fr",
type=str,
help='Volcano Name in french',
required=True)
args = parser.parse_args()
return args
if __name__ == '__main__':
main()