Skip to content

Commit

Permalink
Move file to localfolder
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro committed Aug 14, 2024
1 parent 6a596c4 commit df10e5f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,4 @@ _version.py
# Exampel files
examples/world.parq
examples/world_packed.parq/
exampels/data
14 changes: 10 additions & 4 deletions examples/download.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
from pathlib import Path

try:
import requests
from platformdirs import user_cache_path
except ImportError:
raise ImportError("requests and platformdirs are needed to download data")
raise ImportError("requests are needed to download data")


def download_map(dataset):
if dataset not in ("naturalearth_lowres", "naturalearth_cities"):
raise ValueError(f"Unknown dataset: {dataset}, supported datasets are 'naturalearth_lowres' and 'naturalearth_cities'")
url = f"https://api.github.com/repos/geopandas/geopandas/contents/geopandas/datasets/{dataset}?ref=v0.14.4"
local_dir = user_cache_path() / "spatialpandas" / dataset
local_dir = Path(__file__).parent / "data" / dataset

if local_dir.exists():
return local_dir

response = requests.get(url)
if response.status_code == 200:
if response.ok:
files = response.json()
else:
print(f"Failed to retrieve contents: {response.status_code}")
Expand All @@ -32,3 +33,8 @@ def download_map(dataset):
f.write(file_response.content)

return local_dir


if __name__ == "__main__":
download_map("naturalearth_lowres")
download_map("naturalearth_cities")
1 change: 0 additions & 1 deletion pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ distributed = "*"
geopandas-base = "*"
holoviews = "*"
matplotlib-base = "*"
platformdirs = "*"
pyogrio = "*"
requests = "*"

Expand Down

0 comments on commit df10e5f

Please sign in to comment.