|
| 1 | +import importlib.metadata |
1 | 2 | import json |
2 | 3 | import sys |
3 | 4 | from datetime import datetime |
@@ -38,6 +39,38 @@ def band_subset( |
38 | 39 | print(json.dumps(item.to_dict())) |
39 | 40 |
|
40 | 41 |
|
| 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 | + |
41 | 74 | @app.command(no_args_is_help=True) |
42 | 75 | def wrap_items( |
43 | 76 | collection: str, |
|
0 commit comments