From 9f90a34309ff19c869cab38cfd519628f9983ef8 Mon Sep 17 00:00:00 2001 From: jonhealy1 Date: Thu, 28 Mar 2024 22:48:50 +0800 Subject: [PATCH] fix docstring --- data_loader/data_loader.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/data_loader/data_loader.py b/data_loader/data_loader.py index a5092157..91909c7c 100644 --- a/data_loader/data_loader.py +++ b/data_loader/data_loader.py @@ -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") @@ -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") @@ -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']}") @@ -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()