Skip to content
Snippets Groups Projects
Commit 0140944b authored by Carsten Hinz's avatar Carsten Hinz
Browse files

added comment on possible duration of request

parent d21543ec
No related branches found
No related tags found
1 merge request!11Creation of first beta release version
%% Cell type:code id: tags:
``` python
from datetime import datetime
#samping monthly or daily
sampling = "monthly"
start = datetime(2010,1,1)
end = datetime(2011,1,1)
print(start.date(), end.date())
print(start.isoformat(), end.isoformat())
```
%% Cell type:code id: tags:
``` python
import requests
response = requests.get(
"https://toar-data.fz-juelich.de/api/v2/analysis/statistics/",
params={
"daterange": f"{start.isoformat()},{end.isoformat()}", # 1-year
"variable_id": 5,
"statistics": "mean",
"sampling": sampling, # daily sampling
"min_data_capture": 0,
"limit": "None", # get all timeseries
"format": "by_statistic",
"metadata_scheme": "basic"
}
)
```
%% Cell type:code id: tags:
``` python
print(response.status_code)
status_endpoint = response.json()["status"]
print(status_endpoint)
```
%% Cell type:code id: tags:
``` python
#this cell can run 30minutes or longer.
import time
waiting_for_data = True
start_time = time.time()
while waiting_for_data:
time.sleep(30)
response = requests.get(status_endpoint)
waiting_for_data = (response.headers["Content-Type"] == "application/json")
response_time = time.time() - start_time
print(response_time)
```
%% Cell type:code id: tags:
``` python
response.headers["Content-Type"], response.headers["Content-Length"]
```
%% Cell type:code id: tags:
``` python
from pathlib import Path
outDir = Path("data")
outDir.mkdir(parents=False, exist_ok=True)
fn = outDir / f"{sampling}_{start.date()}_{end.date()}.zip"
with open(fn, "w+b") as sample_file:
sample_file.write(response.content)
print(f"Wrote outout to file [path/to/toargridding]/tests/{fn}")
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment