1
- import click
2
- import os
3
1
import json
2
+ import os
3
+
4
+ import click
4
5
import requests
5
6
6
7
DATA_DIR = os .path .join (os .path .dirname (__file__ ), "setup_data/" )
7
8
STAC_API_BASE_URL = "http://localhost:8083"
8
9
10
+
9
11
def load_data (filename ):
12
+ """Load json data."""
10
13
with open (os .path .join (DATA_DIR , filename )) as file :
11
14
return json .load (file )
12
15
16
+
13
17
def load_collection (collection_id ):
18
+ """Load stac collection into the database."""
14
19
collection = load_data ("collection.json" )
15
20
collection ["id" ] = collection_id
16
21
try :
@@ -24,7 +29,9 @@ def load_collection(collection_id):
24
29
except requests .ConnectionError :
25
30
click .secho ("failed to connect" )
26
31
32
+
27
33
def load_items ():
34
+ """Load stac items into the database."""
28
35
feature_collection = load_data ("sentinel-s2-l2a-cogs_0_100.json" )
29
36
collection = "test-collection"
30
37
load_collection (collection )
@@ -34,8 +41,10 @@ def load_items():
34
41
feature ["stac_extensions" ] = []
35
42
feature ["stac_version" ] = "1.0.0"
36
43
feature ["collection" ] = "test-collection"
37
- resp = requests .post (f"{ STAC_API_BASE_URL } /collections/{ collection } /items" , json = feature )
38
-
44
+ resp = requests .post (
45
+ f"{ STAC_API_BASE_URL } /collections/{ collection } /items" , json = feature
46
+ )
47
+
39
48
if resp .status_code == 200 :
40
49
print (f"Status code: { resp .status_code } " )
41
50
print (f"Added item: { feature ['id' ]} " )
@@ -45,4 +54,5 @@ def load_items():
45
54
except requests .ConnectionError :
46
55
click .secho ("failed to connect" )
47
56
57
+
48
58
load_items ()
0 commit comments