Skip to content

Commit fcf3f86

Browse files
committed
feat: added cli option for metadata updates
1 parent 25a86ed commit fcf3f86

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/eodm/cli/transform/apps/metadata.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import importlib.metadata
12
import json
23
import sys
34
from datetime import datetime
@@ -38,6 +39,38 @@ def band_subset(
3839
print(json.dumps(item.to_dict()))
3940

4041

42+
@app.command(no_args_is_help=True)
43+
def update_metadata(
44+
remove_earthsearch: bool = True,
45+
remove_canonical_link: bool = True,
46+
items: Annotated[typer.FileText, typer.Argument()] = sys.stdin, # type: ignore
47+
) -> None:
48+
"""
49+
Update metadata of STAC ITEMS from FILES read from STDIN.
50+
"""
51+
for i in items:
52+
item = pystac.Item.from_dict(json.loads(i))
53+
item.properties["created"] = datetime.now().isoformat()
54+
item.properties["updated"] = datetime.now().isoformat()
55+
56+
if remove_earthsearch:
57+
item.properties.pop("earthsearch:s3_path", None)
58+
item.properties.pop("earthsearch:payload_id", None)
59+
item.properties.pop("earthsearch:boa_offset_applied", None)
60+
61+
if remove_canonical_link:
62+
item.links = [
63+
link for link in item.links if link.rel != pystac.RelType.CANONICAL
64+
]
65+
66+
for ext in item.stac_extensions:
67+
if "processing" in ext:
68+
item.properties["processing:software"] = {
69+
"eodm": importlib.metadata.version("eodm")
70+
}
71+
print(json.dumps(item.to_dict()))
72+
73+
4174
@app.command(no_args_is_help=True)
4275
def wrap_items(
4376
collection: str,

0 commit comments

Comments
 (0)