Skip to content

Commit

Permalink
Merge branch 'main' into ijsselmeer_model
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielTollenaar committed Nov 7, 2023
2 parents 55bfb91 + b343c71 commit 0c217a6
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -14,12 +14,12 @@ repos:
exclude: '.teamcity'
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.291
rev: v0.1.3
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/psf/black
rev: 23.9.1
rev: 23.10.1
hooks:
- id: black
- id: black-jupyter
Expand All @@ -28,6 +28,6 @@ repos:
hooks:
- id: nbstripout
- repo: https://github.com/crate-ci/typos
rev: v1.16.18
rev: v1.16.21
hooks:
- id: typos
60 changes: 60 additions & 0 deletions docs/thegoodcloud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Connecting The Good Cloud

## Modules
Just `os`, `pathlib`, `requests` are required to get started
```
import os
from pathlib import Path
import requests
```

## global variables
We define a few global variables, `RIBASIM_NL_CLOUD_PASS` is to be supplied as an OOS environment variable.
You need to get one from Deltares first.

```
RIBASIM_NL_CLOUD_PASS = os.getenv("RIBASIM_NL_CLOUD_PASS")
RIBASIM_NL_CLOUD_USER = "nhi_api"
WEBDAV_URL = "https://deltares.thegood.cloud/remote.php/dav"
BASE_URL = f"{WEBDAV_URL}/files/{RIBASIM_NL_CLOUD_USER}/D-HYDRO modeldata"
try:
assert RIBASIM_NL_CLOUD_PASS is not None
except AssertionError:
raise ValueError(
"Put RIBASIM_NL_CLOUD_PASS in your OS environment variables first."
)
```

## Local path and remote URL
An example-file, `my_file.ext` to upload. Please be aware to use a file_name without spaces (`" "`)
```
path = Path("my_file.ext")
url = f"{BASE_URL}/test_files/{path.name}"
```

## Uploading a file


```
def upload_file(url, path):
with open(path, "rb") as f:
r = requests.put(
url, data=f, auth=(RIBASIM_NL_CLOUD_USER, RIBASIM_NL_CLOUD_PASS)
)
r.raise_for_status()
upload_file(url, path)
```

## Downloading a file

```
def download_file(url, path):
r = requests.get(url, auth=(RIBASIM_NL_CLOUD_USER, RIBASIM_NL_CLOUD_PASS))
r.raise_for_status()
with open(path, "wb") as f:
f.write(r.content)
download_file(url, path)
```

0 comments on commit 0c217a6

Please sign in to comment.