Skip to content

Commit

Permalink
fix: links on items
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski committed Nov 9, 2024
1 parent de690c2 commit 9919501
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
22 changes: 6 additions & 16 deletions src/heystac/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import sys

import click

from .config import Config
Expand All @@ -21,24 +19,16 @@ def bootstrap() -> None:


@click.command()
@click.argument("id", default=None)
@click.option("--all", is_flag=True, help="Crawl every catalog")
def crawl(id: str | None, all: bool) -> None:
@click.argument("id")
def crawl(id: str) -> None:
"""Crawl a STAC API.
We don't crawl every API because that'd be expensive.
If id == "all" then we'll crawl all the catalogs — this could take a while.
"""
config = Config()
if id is None:
if all:
for id in config.catalogs.keys():
config.crawl(id)
else:
print(
"To crawl every catalog, pass the --all flag",
file=sys.stderr,
)
sys.exit(1)
if id == "all":
for id in config.catalogs.keys():
config.crawl(id)
else:
config.crawl(id)

Expand Down
6 changes: 3 additions & 3 deletions src/heystac/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def crawl(self, id: str) -> None:
catalog.links.append(Link(href="../catalog.json", rel="root"))
catalog.links.append(Link(href="../catalog.json", rel="parent"))

progress_bar = tqdm.tqdm(total=len(child_links) * 2)
progress_bar = tqdm.tqdm(total=len(child_links) * 2, desc=id)
if (self.stac_path / id).exists():
shutil.rmtree(self.stac_path / id)
for link in child_links:
Expand All @@ -131,8 +131,8 @@ def crawl(self, id: str) -> None:
for item in items.features:
item.remove_structural_links()
child.links.append(Link(href=f"./{item.id}.json", rel="item"))
item.links.append(Link(href="../collection.json", rel="parent"))
item.links.append(Link(href="../collection.json", rel="collection"))
item.links.append(Link(href="./collection.json", rel="parent"))
item.links.append(Link(href="./collection.json", rel="collection"))
item.links.append(Link(href="../../../catalog.json", rel="root"))
self.write_stac(item, f"{id}/{child.id}/{item.id}.json")
self.write_stac(child, f"{id}/{child.id}/collection.json")
Expand Down
2 changes: 1 addition & 1 deletion stac
Submodule stac updated 139 files

0 comments on commit 9919501

Please sign in to comment.