Skip to content

Commit

Permalink
fix docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhealy1 committed Mar 28, 2024
1 parent 50c3d26 commit 9f90a34
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions data_loader/data_loader.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
"""Database ingestion script."""
import json
import os

import click
import requests

# Define the directory where your data files are located
DATA_DIR = os.path.join(os.path.dirname(__file__), "setup_data/")


def load_data(filename):
"""Load json data from a file."""
with open(os.path.join(DATA_DIR, filename)) as file:
return json.load(file)


def load_collection(base_url, collection_id):
"""Load a STAC collection into the database."""
collection = load_data("collection.json")
Expand All @@ -27,6 +30,7 @@ def load_collection(base_url, collection_id):
except requests.ConnectionError:
click.secho("Failed to connect", fg="red")


def load_items(base_url, collection_id):
"""Load STAC items into the database."""
feature_collection = load_data("sentinel-s2-l2a-cogs_0_100.json")
Expand All @@ -36,7 +40,9 @@ def load_items(base_url, collection_id):
for feature in feature_collection["features"]:
try:
feature["collection"] = collection
resp = requests.post(f"{base_url}/collections/{collection}/items", json=feature)
resp = requests.post(
f"{base_url}/collections/{collection}/items", json=feature
)
if resp.status_code == 200:
click.echo(f"Status code: {resp.status_code}")
click.echo(f"Added item: {feature['id']}")
Expand All @@ -46,14 +52,18 @@ def load_items(base_url, collection_id):
except requests.ConnectionError:
click.secho("Failed to connect", fg="red")


@click.command()
@click.option('--base-url', required=True, help='Base URL of the STAC API')
@click.option('--collection-id', default='test-collection', help='ID of the collection to which items are added')
@click.option("--base-url", required=True, help="Base URL of the STAC API")
@click.option(
"--collection-id",
default="test-collection",
help="ID of the collection to which items are added",
)
def main(base_url, collection_id):
"""
Load STAC items into the database.
"""
"""Load STAC items into the database."""
load_items(base_url, collection_id)

if __name__ == '__main__':

if __name__ == "__main__":
main()

0 comments on commit 9f90a34

Please sign in to comment.