Skip to content

Commit 45fca70

Browse files
refactor: clean up code formatting and improve readability in notebook and test files
1 parent 9e36e7f commit 45fca70

File tree

3 files changed

+50
-10
lines changed

3 files changed

+50
-10
lines changed

operator-tools/submit_stac_items_notebook.ipynb

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
}
2828
],
2929
"source": [
30-
"import getpass\n",
3130
"import json\n",
32-
"import os\n",
3331
"from pathlib import Path\n",
3432
"\n",
3533
"import pandas as pd\n",
@@ -63,7 +61,15 @@
6361
"execution_count": null,
6462
"metadata": {},
6563
"outputs": [],
66-
"source": "# STAC API Configuration\nSTAC_API_URL = \"https://stac.core.eopf.eodc.eu/\"\n\n# Webhook Configuration\nWEBHOOK_URL = \"http://localhost:12000/samples\"\n\nprint(\"✅ Configuration loaded\")"
64+
"source": [
65+
"# STAC API Configuration\n",
66+
"STAC_API_URL = \"https://stac.core.eopf.eodc.eu/\"\n",
67+
"\n",
68+
"# Webhook Configuration\n",
69+
"WEBHOOK_URL = \"http://localhost:12000/samples\"\n",
70+
"\n",
71+
"print(\"✅ Configuration loaded\")"
72+
]
6773
},
6874
{
6975
"cell_type": "markdown",
@@ -426,7 +432,41 @@
426432
"execution_count": null,
427433
"metadata": {},
428434
"outputs": [],
429-
"source": "def submit_item_to_pipeline(item_url: str, target_collection: str) -> bool:\n \"\"\"\n Submit a single STAC item to the data pipeline via HTTP webhook.\n\n Args:\n item_url: The self-link URL of the STAC item\n target_collection: The target collection for processing\n\n Returns:\n True if successful, False otherwise\n \"\"\"\n try:\n # Create payload\n payload = {\n \"source_url\": item_url,\n \"collection\": target_collection,\n \"action\": \"convert-v1-s2\", # specify the action to use the V1 S2 trigger\n }\n\n # Submit via HTTP webhook endpoint\n message = json.dumps(payload)\n response = requests.post(\n WEBHOOK_URL,\n data=message,\n headers={\"Content-Type\": \"application/json\"},\n )\n \n response.raise_for_status()\n return True\n\n except Exception as e:\n print(f\"❌ Error submitting item: {e}\")\n return False"
435+
"source": [
436+
"def submit_item_to_pipeline(item_url: str, target_collection: str) -> bool:\n",
437+
" \"\"\"\n",
438+
" Submit a single STAC item to the data pipeline via HTTP webhook.\n",
439+
"\n",
440+
" Args:\n",
441+
" item_url: The self-link URL of the STAC item\n",
442+
" target_collection: The target collection for processing\n",
443+
"\n",
444+
" Returns:\n",
445+
" True if successful, False otherwise\n",
446+
" \"\"\"\n",
447+
" try:\n",
448+
" # Create payload\n",
449+
" payload = {\n",
450+
" \"source_url\": item_url,\n",
451+
" \"collection\": target_collection,\n",
452+
" \"action\": \"convert-v1-s2\", # specify the action to use the V1 S2 trigger\n",
453+
" }\n",
454+
"\n",
455+
" # Submit via HTTP webhook endpoint\n",
456+
" message = json.dumps(payload)\n",
457+
" response = requests.post(\n",
458+
" WEBHOOK_URL,\n",
459+
" data=message,\n",
460+
" headers={\"Content-Type\": \"application/json\"},\n",
461+
" )\n",
462+
"\n",
463+
" response.raise_for_status()\n",
464+
" return True\n",
465+
"\n",
466+
" except Exception as e:\n",
467+
" print(f\"❌ Error submitting item: {e}\")\n",
468+
" return False"
469+
]
430470
},
431471
{
432472
"cell_type": "code",
@@ -3177,4 +3217,4 @@
31773217
},
31783218
"nbformat": 4,
31793219
"nbformat_minor": 4
3180-
}
3220+
}

stac/S2A_MSIL2A_20250831T103701_N0511_R008_T31TFL_20250831T145420_with_alternate.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,4 +600,4 @@
600600
"https://stac-extensions.github.io/alternate-assets/v1.2.0/schema.json",
601601
"https://stac-extensions.github.io/storage/v2.0.0/schema.json"
602602
]
603-
}
603+
}

tests/test_alternate_extension.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import json
55
from pathlib import Path
66

7-
from pystac import Item
8-
97

108
def https_to_s3(https_url: str, endpoint: str) -> str | None:
119
"""Convert https:// URL back to s3:// URL if it matches the S3 endpoint pattern."""
@@ -53,7 +51,7 @@ def add_alternate_s3_to_item(item_dict: dict, s3_endpoint: str) -> dict:
5351

5452
# Add alternate to each asset
5553
modified_count = 0
56-
for asset_key, asset in item_dict.get("assets", {}).items():
54+
for _, asset in item_dict.get("assets", {}).items():
5755
href = asset.get("href", "")
5856

5957
# Skip non-HTTPS URLs or thumbnails
@@ -85,7 +83,9 @@ def add_alternate_s3_to_item(item_dict: dict, s3_endpoint: str) -> dict:
8583
def main():
8684
"""Test the alternate extension with the sample JSON."""
8785
# Read the sample JSON
88-
sample_file = Path(__file__).parent / "S2A_MSIL2A_20250831T103701_N0511_R008_T31TFL_20250831T145420.json"
86+
sample_file = (
87+
Path(__file__).parent / "S2A_MSIL2A_20250831T103701_N0511_R008_T31TFL_20250831T145420.json"
88+
)
8989

9090
if not sample_file.exists():
9191
print(f"❌ Sample file not found: {sample_file}")

0 commit comments

Comments
 (0)