Skip to content

Commit

Permalink
Create thegoodcloud.md (#29)
Browse files Browse the repository at this point in the history
@rbruijnshkv, see instructions how to work with `thegoodcloud in
[docs/thegoodcloud.md](https://github.com/Deltares/Ribasim-NL/compare/thegoodcloud_instructions?expand=1#diff-c27c31a9110587e188c6a0fc61c14002fdef879390b34f71e0fb0736c6d50c72).

Feel free to make it clearer if necessary and to merge it yourself if
done

---------

Co-authored-by: Martijn Visser <[email protected]>
  • Loading branch information
D2Hydro and visr authored Oct 31, 2023
1 parent c8f2e50 commit 7de7cd1
Showing 1 changed file with 60 additions and 0 deletions.
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 7de7cd1

Please sign in to comment.