python-esios 0.1.0__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python-esios-0.1.0/python_esios.egg-info → python_esios-0.1.2}/PKG-INFO +1 -1
- {python-esios-0.1.0 → python_esios-0.1.2}/esios/api_client.py +7 -2
- {python-esios-0.1.0 → python_esios-0.1.2}/esios/endpoints/indicators/__init__.py +0 -2
- {python-esios-0.1.0 → python_esios-0.1.2/python_esios.egg-info}/PKG-INFO +1 -1
- {python-esios-0.1.0 → python_esios-0.1.2}/python_esios.egg-info/SOURCES.txt +0 -5
- {python-esios-0.1.0 → python_esios-0.1.2}/setup.py +1 -1
- python-esios-0.1.0/esios/endpoints/archives/__init__.py +0 -0
- python-esios-0.1.0/esios/endpoints/archives/archives.py +0 -32
- python-esios-0.1.0/esios/tests/__init__.py +0 -0
- python-esios-0.1.0/esios/tests/test_api_client.py +0 -15
- python-esios-0.1.0/esios/tests/test_indicators.py +0 -20
- {python-esios-0.1.0 → python_esios-0.1.2}/LICENSE +0 -0
- {python-esios-0.1.0 → python_esios-0.1.2}/README.md +0 -0
- {python-esios-0.1.0 → python_esios-0.1.2}/esios/__init__.py +0 -0
- {python-esios-0.1.0 → python_esios-0.1.2}/esios/endpoints/__init__.py +0 -0
- {python-esios-0.1.0 → python_esios-0.1.2}/python_esios.egg-info/dependency_links.txt +0 -0
- {python-esios-0.1.0 → python_esios-0.1.2}/python_esios.egg-info/requires.txt +0 -0
- {python-esios-0.1.0 → python_esios-0.1.2}/python_esios.egg-info/top_level.txt +0 -0
- {python-esios-0.1.0 → python_esios-0.1.2}/setup.cfg +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import requests
|
|
2
|
+
import os
|
|
2
3
|
|
|
3
4
|
class APIClient:
|
|
4
5
|
base_url = 'https://api.esios.ree.es'
|
|
@@ -8,7 +9,11 @@ class APIClient:
|
|
|
8
9
|
'Host': 'api.esios.ree.es',
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
def __init__(self, api_key):
|
|
12
|
+
def __init__(self, api_key=None):
|
|
13
|
+
if api_key is None:
|
|
14
|
+
api_key = os.getenv('ESIOS_API_KEY') # Try to get the API key from environment variable
|
|
15
|
+
if api_key is None:
|
|
16
|
+
raise ValueError("API key must be provided either through constructor or as an environment variable 'ESIOS_API_KEY'")
|
|
12
17
|
self.api_key = api_key
|
|
13
18
|
self.headers['x-api-key'] = self.api_key
|
|
14
19
|
|
|
@@ -16,4 +21,4 @@ class APIClient:
|
|
|
16
21
|
url = self.base_url + endpoint
|
|
17
22
|
response = requests.request(method, url, headers=self.headers, params=params, json=data)
|
|
18
23
|
response.raise_for_status()
|
|
19
|
-
return response
|
|
24
|
+
return response
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import pandas as pd
|
|
2
2
|
from esios.api_client import APIClient
|
|
3
3
|
import html
|
|
4
|
-
from bs4 import BeautifulSoup
|
|
5
4
|
|
|
6
5
|
class Indicators(APIClient):
|
|
7
6
|
def __init__(self, api_key):
|
|
@@ -29,7 +28,6 @@ class Indicators(APIClient):
|
|
|
29
28
|
if df:
|
|
30
29
|
df = pd.DataFrame(data['indicators'])
|
|
31
30
|
df['description'] = df['description'].apply(html.unescape)
|
|
32
|
-
df
|
|
33
31
|
return df.set_index('id')
|
|
34
32
|
else:
|
|
35
33
|
return data
|
|
@@ -4,12 +4,7 @@ setup.py
|
|
|
4
4
|
esios/__init__.py
|
|
5
5
|
esios/api_client.py
|
|
6
6
|
esios/endpoints/__init__.py
|
|
7
|
-
esios/endpoints/archives/__init__.py
|
|
8
|
-
esios/endpoints/archives/archives.py
|
|
9
7
|
esios/endpoints/indicators/__init__.py
|
|
10
|
-
esios/tests/__init__.py
|
|
11
|
-
esios/tests/test_api_client.py
|
|
12
|
-
esios/tests/test_indicators.py
|
|
13
8
|
python_esios.egg-info/PKG-INFO
|
|
14
9
|
python_esios.egg-info/SOURCES.txt
|
|
15
10
|
python_esios.egg-info/dependency_links.txt
|
|
File without changes
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import pandas as pd
|
|
3
|
-
from esios.api_client import APIClient
|
|
4
|
-
from esios.utils import preprocessing
|
|
5
|
-
|
|
6
|
-
class Archives(APIClient):
|
|
7
|
-
def __init__(self, api_key):
|
|
8
|
-
super().__init__(api_key)
|
|
9
|
-
|
|
10
|
-
def list(self, params=None):
|
|
11
|
-
endpoint = "/archives"
|
|
12
|
-
response = self._api_call('GET', endpoint)
|
|
13
|
-
return response.json()
|
|
14
|
-
|
|
15
|
-
def get(self, archive_id, params=None, write_home=None):
|
|
16
|
-
endpoint = f"/archives/{archive_id}/download"
|
|
17
|
-
response = self._api_call('GET', endpoint, params=params)
|
|
18
|
-
|
|
19
|
-
if write_home:
|
|
20
|
-
path = os.path.join(write_home, f'{archive_id}.zip')
|
|
21
|
-
with open(path, 'wb') as f:
|
|
22
|
-
f.write(response.content)
|
|
23
|
-
preprocessing.unzip_files_and_remove(path)
|
|
24
|
-
|
|
25
|
-
return ArchiveData(response.content)
|
|
26
|
-
|
|
27
|
-
class ArchiveData:
|
|
28
|
-
def __init__(self, data):
|
|
29
|
-
self.data = data
|
|
30
|
-
|
|
31
|
-
def to_pandas(self):
|
|
32
|
-
return pd.DataFrame(self.data)
|
|
File without changes
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import unittest
|
|
2
|
-
from esios.api_client import APIClient
|
|
3
|
-
|
|
4
|
-
class TestAPIClient(unittest.TestCase):
|
|
5
|
-
|
|
6
|
-
def setUp(self):
|
|
7
|
-
self.api_client = APIClient(api_key="test_key")
|
|
8
|
-
|
|
9
|
-
def test_api_call(self):
|
|
10
|
-
# This test is just a placeholder
|
|
11
|
-
# You would mock requests and test _api_call
|
|
12
|
-
pass
|
|
13
|
-
|
|
14
|
-
if __name__ == '__main__':
|
|
15
|
-
unittest.main()
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import unittest
|
|
2
|
-
from esios.endpoints.indicators import Indicators
|
|
3
|
-
|
|
4
|
-
class TestIndicators(unittest.TestCase):
|
|
5
|
-
|
|
6
|
-
def setUp(self):
|
|
7
|
-
self.indicators_client = Indicators(api_key="test_key")
|
|
8
|
-
|
|
9
|
-
def test_list(self):
|
|
10
|
-
# This test is just a placeholder
|
|
11
|
-
# You would mock requests and test the list method
|
|
12
|
-
pass
|
|
13
|
-
|
|
14
|
-
def test_get(self):
|
|
15
|
-
# This test is just a placeholder
|
|
16
|
-
# You would mock requests and test the get method
|
|
17
|
-
pass
|
|
18
|
-
|
|
19
|
-
if __name__ == '__main__':
|
|
20
|
-
unittest.main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|