Newer
Older
{
"cells": [
{
"cell_type": "code",
"execution_count": 47,
"metadata": {},
"outputs": [],
"source": [
"import copernicusmarine\n",
"from io import BytesIO\n",
"import pycurl\n",
"\n",
"#copernicusmarine.login()\n",
"import logging\n",
"logging.getLogger(\"copernicus_marine_root_logger\").setLevel(\"ERROR\")\n",
"\n",

Karine PARRA
committed
"def get_curl(url, params = None, follow_location: int = 0):\n",
" buffer = BytesIO()\n",
" c = pycurl.Curl()\n",
" c.setopt(pycurl.URL, url)\n",
" c.setopt(c.WRITEDATA, buffer)\n",
" c.setopt(c.SSL_VERIFYPEER, 1)\n",
" c.setopt(c.SSL_VERIFYHOST, 2)\n",
" c.setopt(c.CAINFO, \"ca-bundle.crt\")\n",
" c.setopt(c.FOLLOWLOCATION, follow_location)\n",
" if params:\n",
" c.setopt(c.HTTPHEADER,params) \n",
" c.perform()\n",
" http_code = c.getinfo(c.RESPONSE_CODE)\n",
" c.close()\n",
" answer = buffer.getvalue().decode('utf-8')\n",
" if http_code != 200:\n",
" raise ValueError(f\"Error {str(http_code)} - {answer}\")\n",
"def checkUrlCopernicus(dataset_id: str, typeDatas: str): \n",
" global healthCheck\n",
" try:\n",
" copernicusmarine.open_dataset(dataset_id=dataset_id)\n",
" if \"Historical\" in typeDatas:\n",
" healthCheck += \"\\n\"\n",
" healthCheck += \"\\n\" + f\"{typeDatas} : connection OK\"\n",
" except ValueError as err:\n",
" healthCheck += \"\\n\" + f\"{typeDatas} : connection ERROR - {err}\"\n",
"def checkUrl(url: str, typeDatas: str): \n",
" global healthCheck\n",

Karine PARRA
committed
" get_curl(url)\n",
" if \"Historical\" in typeDatas:\n",
" healthCheck += \"\\n\"\n",
" healthCheck += \"\\n\" + f\"{typeDatas} : connection OK\"\n",
" except ValueError as err:\n",
" healthCheck += \"\\n\" + f\"{typeDatas} : connection ERROR - {err}\"\n",
"healthCheck += \"\\n\" + \"------ COPERNICUS ------\"\n",
"checkUrlCopernicus(\"cmems_mod_ibi_phy_my_0.083deg-3D_P1D-m\", \"Historical temperature datas\")\n",
"checkUrlCopernicus(\"cmems_mod_ibi_phy_anfc_0.027deg-3D_P1D-m\", \"Forecast temperature datas\")\n",
"checkUrlCopernicus(\"cmems_mod_ibi_bgc_my_0.083deg-3D_P1D-m\", \"Historical oxygen datas\")\n",
"checkUrlCopernicus(\"cmems_mod_ibi_bgc_anfc_0.027deg-3D_P1D-m\", \"Forecast oxygen datas\")\n",
"checkUrlCopernicus(\"cmems_mod_ibi_wav_my_0.027deg_PT1H-i\", \"Historical waves datas\")\n",
"checkUrlCopernicus(\"cmems_mod_ibi_wav_anfc_0.05deg_PT1H-i\", \"Forecast waves datas\")\n",
"healthCheck += \"\\n\\n\" + \"------ HUB'EAU ------\" \n",
"checkUrl(\"https://hubeau.eaufrance.fr/api/v1/hydrometrie/obs_elab?code_entite=O919001001&fields=date_obs,resultat_obs&grandeur_hydro_elab=QmJ&size=20000\",\n",
" \"Historical Garonne datas\")\n",
"checkUrl(\"https://hubeau.eaufrance.fr/api/v1/hydrometrie/observations_tr?code_entite=O919001001&grandeur_hydro=Q&size=20000&sort=asc&fields=date_obs,resultat_obs\",\n",
" \"Forecast Garonne datas\")\n",
"checkUrl(\"https://hubeau.eaufrance.fr/api/v1/hydrometrie/obs_elab?code_entite=P555001001&fields=date_obs,resultat_obs&grandeur_hydro_elab=QmJ&size=20000\",\n",
" \"Historical Dordogne datas\")\n",
"checkUrl(\"https://hubeau.eaufrance.fr/api/v1/hydrometrie/observations_tr?code_entite=P555001001&grandeur_hydro=Q&size=20000&sort=asc&fields=date_obs,resultat_obs\",\n",
" \"Forecast Dordogne datas\")\n",
"healthCheck += \"\\n\\n\" + \"------ MAGEST ------\"\n",
"checkUrl(\"https://magest.oasu.u-bordeaux.fr/index.php?pg=graph¶metre=salinites&noKey=1&siteId=4\",\n",
"checkUrl(\"https://magest.oasu.u-bordeaux.fr/index.php?pg=graph¶metre=temperatures&noKey=1&siteId=4\",\n",
" \"Garonne temperature datas\")\n",
"checkUrl(\"https://magest.oasu.u-bordeaux.fr/index.php?pg=graph¶metre=oxygenes&noKey=1&siteId=4\",\n",
" \"Garonne oxygen datas\")\n",
"checkUrl(\"https://magest.oasu.u-bordeaux.fr/index.php?pg=graph¶metre=salinites&noKey=1&siteId=5\",\n",
"checkUrl(\"https://magest.oasu.u-bordeaux.fr/index.php?pg=graph¶metre=temperatures&noKey=1&siteId=5\",\n",
" \"Dordogne temperature datas\")\n",
"checkUrl(\"https://magest.oasu.u-bordeaux.fr/index.php?pg=graph¶metre=oxygenes&noKey=1&siteId=5\",\n",
" \"Dordogne oxygen datas\")\n",
"\n",
"healthCheck += \"\\n\\n\" + \"------ OPEN METEO ------\" \n",
"checkUrl(\"https://archive-api.open-meteo.com/v1/era5?latitude=45.4&longitude=-0.8&hourly=temperature_2m,pressure_msl,windspeed_10m,winddirection_10m\",\n",
" \"Historical datas\")\n",
"checkUrl(\"https://api.open-meteo.com/v1/forecast?latitude=45.4&longitude=-0.8&hourly=temperature_2m,pressure_msl,windspeed_10m,winddirection_10m\",\n",
" \"Forecast datas\")\n",
]
}
],
"metadata": {
"kernelspec": {
"display_name": "gpmb",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
}