python-esios 0.2.4__tar.gz → 0.2.6__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-esios
3
- Version: 0.2.4
3
+ Version: 0.2.6
4
4
  Summary: A Python wrapper for the ESIOS API
5
5
  Home-page: https://github.com/datons/python-esios
6
6
  Author: Jesús López
@@ -0,0 +1,32 @@
1
+ from pathlib import Path
2
+ import pandas as pd
3
+
4
+
5
+ def process_excel_file(path, sheet_name):
6
+ """
7
+ Process an Excel file and return a melted dataframe.
8
+ """
9
+
10
+ if not isinstance(path, Path):
11
+ path = Path(path)
12
+
13
+ sheet_data = pd.read_excel(path, sheet_name=sheet_name, skiprows=0, nrows=1)
14
+ position = sheet_data.columns.get_loc("Indicadores")
15
+
16
+ df = pd.read_excel(
17
+ path, sheet_name=sheet_name, index_col=list(range(position)), skiprows=2
18
+ ).iloc[:, 2:]
19
+
20
+ date = path.stem.split("_")[1]
21
+
22
+ if df.shape[1] > 30:
23
+ date_ = pd.to_datetime(date).tz_localize("Europe/Madrid")
24
+ date_range = pd.date_range(start=date_, periods=df.shape[1], freq="15min")
25
+ df.columns = date_range
26
+ else:
27
+ hour = df.columns.str.split("-", expand=True).get_level_values(0)
28
+ df.columns = pd.to_datetime(date + " " + hour).tz_localize("Europe/Madrid")
29
+
30
+ df = df.melt(ignore_index=False, var_name="datetime").reset_index()
31
+
32
+ return df
@@ -48,10 +48,18 @@ class Indicator:
48
48
  # Remove None values from params
49
49
  params = {k: v for k, v in params.items() if v is not None}
50
50
 
51
- start_date = datetime.strptime(start, '%Y-%m-%d')
52
- end_date = datetime.strptime(end, '%Y-%m-%d')
51
+ start_date = pd.to_datetime(start)
52
+ end_date = pd.to_datetime(end)
53
53
  three_weeks = timedelta(weeks=3)
54
-
54
+
55
+ endpoint = f"indicators/{self.id}"
56
+
57
+ if end_date - start_date <= three_weeks:
58
+ data = self.client._get(endpoint, self.client.public_headers, params=params)
59
+ data = data.get('indicator', {}).get('values', [])
60
+
61
+ return self._to_dataframe(data, column_name)
62
+
55
63
  data_all = []
56
64
 
57
65
  current_start = start_date
@@ -61,7 +69,6 @@ class Indicator:
61
69
  chunk_params['start_date'] = current_start.strftime('%Y-%m-%d')
62
70
  chunk_params['end_date'] = current_end.strftime('%Y-%m-%d') + 'T23:59:59'
63
71
 
64
- endpoint = f"indicators/{self.id}"
65
72
  data = self.client._get(endpoint, self.client.public_headers, params=chunk_params)
66
73
  data_all.extend(data.get('indicator', {}).get('values', []))
67
74
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-esios
3
- Version: 0.2.4
3
+ Version: 0.2.6
4
4
  Summary: A Python wrapper for the ESIOS API
5
5
  Home-page: https://github.com/datons/python-esios
6
6
  Author: Jesús López
@@ -2,10 +2,11 @@ LICENSE
2
2
  README.md
3
3
  setup.py
4
4
  esios/__init__.py
5
- esios/archives.py
6
5
  esios/client.py
7
6
  esios/indicators.py
8
7
  esios/offer_indicators.py
8
+ esios/archives/__init__.py
9
+ esios/archives/preprocessing.py
9
10
  python_esios.egg-info/PKG-INFO
10
11
  python_esios.egg-info/SOURCES.txt
11
12
  python_esios.egg-info/dependency_links.txt
@@ -2,27 +2,28 @@ from setuptools import setup, find_packages
2
2
 
3
3
 
4
4
  from pathlib import Path
5
+
5
6
  this_directory = Path(__file__).parent
6
- long_description = (this_directory / "README.md").read_text(encoding='utf-8')
7
+ long_description = (this_directory / "README.md").read_text(encoding="utf-8")
7
8
 
8
9
  setup(
9
- name='python-esios',
10
- version='0.2.4',
10
+ name="python-esios",
11
+ version="0.2.6",
11
12
  packages=find_packages(),
12
13
  install_requires=[
13
- 'requests',
14
- 'pandas',
14
+ "requests",
15
+ "pandas",
15
16
  ],
16
17
  author="Jesús López",
17
18
  author_email="jesus.lopez@datons.ai",
18
19
  description="A Python wrapper for the ESIOS API",
19
20
  long_description=long_description,
20
- long_description_content_type='text/markdown',
21
+ long_description_content_type="text/markdown",
21
22
  url="https://github.com/datons/python-esios",
22
23
  classifiers=[
23
24
  "Programming Language :: Python :: 3",
24
25
  "License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
25
26
  "Operating System :: OS Independent",
26
27
  ],
27
- python_requires='>=3.6',
28
+ python_requires=">=3.6",
28
29
  )
File without changes
File without changes
File without changes