Skip to content

Commit

Permalink
merge tablefile and cubefile PR and use latest config module
Browse files Browse the repository at this point in the history
  • Loading branch information
pmayd committed Jul 30, 2022
1 parent 59e58e2 commit 1779053
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 29 deletions.
12 changes: 10 additions & 2 deletions nb/download_tablefile.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Error while loading the config file. Could not find C:\\Users\\micha\\AppData\\Local\\Temp\\pytest-of-micha\\pytest-78\\.pygenesis3\\config.ini. Please make sure to run init_config() first. \n"
]
}
],
"source": [
"import pandas as pd\n",
"from pygenesis.table import get_tablefile_data"
Expand Down Expand Up @@ -640,7 +648,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.9.7 ('pygenesis')",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand Down
24 changes: 12 additions & 12 deletions nb/parse_cube.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"metadata": {
"scrolled": true
},
Expand All @@ -69,16 +69,16 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(str, 106)"
"(str, 79264)"
]
},
"execution_count": 5,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -89,13 +89,13 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['* Der Benutzer DEI6I4B3UW der Benutzergruppe DE0142 hat am 28.07.2022 um 13:14:40 diesen Export angestossen.',\n",
"['* Der Benutzer DEI6I4B3UW der Benutzergruppe DE0142 hat am 30.07.2022 um 20:43:34 diesen Export angestossen.',\n",
" 'K;DQ;FACH-SCHL;GHH-ART;GHM-WERTE-JN;GENESIS-VBD;REGIOSTAT;EU-VBD;\"mit Werten\"',\n",
" 'D;47414BJ002;;N;N;N;N',\n",
" 'K;DQ-ERH;FACH-SCHL',\n",
Expand All @@ -117,7 +117,7 @@
" 'D;DG;WZ08-49-01;NOMINAL;2020;96.0;e;;0.0']"
]
},
"execution_count": 8,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -137,7 +137,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -146,7 +146,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 7,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -193,7 +193,7 @@
" [2023 rows x 8 columns]}"
]
},
"execution_count": 9,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -204,7 +204,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 8,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -395,7 +395,7 @@
"[2023 rows x 8 columns]"
]
},
"execution_count": 10,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
Expand Down
7 changes: 0 additions & 7 deletions src/pygenesis/config_loader.py

This file was deleted.

11 changes: 5 additions & 6 deletions src/pygenesis/http_helper.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""Wrapper module for the data endpoint."""
import requests

from pygenesis.config_loader import CONFIG
from pygenesis.config import load_config

# TODO: \global vars init? .env?
base_url = "https://www-genesis.destatis.de/genesisWS/rest/2020"
config = load_config()


def get_response_from_endpoint(
Expand All @@ -22,11 +21,11 @@ def get_response_from_endpoint(
Returns:
requests.Response: the response from destatis
"""
url = f"{base_url}/{endpoint}/{method}"
url = f"{config['GENESIS API']['base_url']}/{endpoint}/{method}"

params |= {
"username": CONFIG["PYGENESIS_USERNAME"],
"password": CONFIG["PYGENESIS_PASSWORD"],
"username": config["GENESIS API"]["username"],
"password": config["GENESIS API"]["password"],
}

response = requests.get(url, params=params)
Expand Down
11 changes: 9 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import pytest

from pygenesis.config import (
DEFAULT_CONFIG_DIR,
DEFAULT_SETTINGS_FILE,
_write_config,
get_config_path_from_settings,
init_config,
load_config,
Expand All @@ -20,6 +20,13 @@ def config_dir(tmp_path_factory):
return config_dir


@pytest.fixture(autouse=True)
def restore_settings():
old_settings = load_settings()
yield
_write_config(old_settings, DEFAULT_SETTINGS_FILE)


def test_settings():
assert DEFAULT_SETTINGS_FILE.exists() and DEFAULT_SETTINGS_FILE.is_file()

Expand Down Expand Up @@ -78,7 +85,7 @@ def test_missing_username(config_dir, caplog):

caplog.clear()

config = load_config()
_ = load_config()

assert caplog.records[0].levelname == "CRITICAL"
assert "Username and/or password are missing!" in caplog.text
Expand Down

0 comments on commit 1779053

Please sign in to comment.