Skip to content

Commit

Permalink
Add MIBGAS downloader
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmunoznovoa committed Jul 16, 2022
1 parent d8e3f1b commit fb9e2c6
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 49 deletions.
147 changes: 99 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,30 @@ print(*prices, sep='\n')

# Resultado
```
{'local_timestamp': '2022-04-13 01:00:00', 'utc_timestamp': '2022-04-12 23:00:00', 'value': 242.75}
{'local_timestamp': '2022-04-13 02:00:00', 'utc_timestamp': '2022-04-13 00:00:00', 'value': 229.77}
{'local_timestamp': '2022-04-13 03:00:00', 'utc_timestamp': '2022-04-13 01:00:00', 'value': 220.0}
{'local_timestamp': '2022-04-13 04:00:00', 'utc_timestamp': '2022-04-13 02:00:00', 'value': 201.85}
{'local_timestamp': '2022-04-13 05:00:00', 'utc_timestamp': '2022-04-13 03:00:00', 'value': 190.9}
{'local_timestamp': '2022-04-13 06:00:00', 'utc_timestamp': '2022-04-13 04:00:00', 'value': 212.32}
{'local_timestamp': '2022-04-13 07:00:00', 'utc_timestamp': '2022-04-13 05:00:00', 'value': 248.74}
{'local_timestamp': '2022-04-13 08:00:00', 'utc_timestamp': '2022-04-13 06:00:00', 'value': 257.02}
{'local_timestamp': '2022-04-13 09:00:00', 'utc_timestamp': '2022-04-13 07:00:00', 'value': 260.0}
{'local_timestamp': '2022-04-13 10:00:00', 'utc_timestamp': '2022-04-13 08:00:00', 'value': 254.25}
{'local_timestamp': '2022-04-13 11:00:00', 'utc_timestamp': '2022-04-13 09:00:00', 'value': 242.75}
{'local_timestamp': '2022-04-13 12:00:00', 'utc_timestamp': '2022-04-13 10:00:00', 'value': 234.99}
{'local_timestamp': '2022-04-13 13:00:00', 'utc_timestamp': '2022-04-13 11:00:00', 'value': 227.67}
{'local_timestamp': '2022-04-13 14:00:00', 'utc_timestamp': '2022-04-13 12:00:00', 'value': 208.0}
{'local_timestamp': '2022-04-13 15:00:00', 'utc_timestamp': '2022-04-13 13:00:00', 'value': 201.18}
{'local_timestamp': '2022-04-13 16:00:00', 'utc_timestamp': '2022-04-13 14:00:00', 'value': 196.0}
{'local_timestamp': '2022-04-13 17:00:00', 'utc_timestamp': '2022-04-13 15:00:00', 'value': 200.47}
{'local_timestamp': '2022-04-13 18:00:00', 'utc_timestamp': '2022-04-13 16:00:00', 'value': 221.2}
{'local_timestamp': '2022-04-13 19:00:00', 'utc_timestamp': '2022-04-13 17:00:00', 'value': 219.28}
{'local_timestamp': '2022-04-13 20:00:00', 'utc_timestamp': '2022-04-13 18:00:00', 'value': 242.36}
{'local_timestamp': '2022-04-13 21:00:00', 'utc_timestamp': '2022-04-13 19:00:00', 'value': 254.0}
{'local_timestamp': '2022-04-13 22:00:00', 'utc_timestamp': '2022-04-13 20:00:00', 'value': 259.0}
{'local_timestamp': '2022-04-13 23:00:00', 'utc_timestamp': '2022-04-13 21:00:00', 'value': 250.0}
{'local_timestamp': '2022-04-14 00:00:00', 'utc_timestamp': '2022-04-13 22:00:00', 'value': 231.94}
{'local_timestamp': '2022-04-13 01:00:00', 'utc_timestamp': '2022-04-12 23:00:00', 'value': 242.75, 'zone': 'es'}
{'local_timestamp': '2022-04-13 02:00:00', 'utc_timestamp': '2022-04-13 00:00:00', 'value': 229.77, 'zone': 'es'}
{'local_timestamp': '2022-04-13 03:00:00', 'utc_timestamp': '2022-04-13 01:00:00', 'value': 220.0, 'zone': 'es'}
{'local_timestamp': '2022-04-13 04:00:00', 'utc_timestamp': '2022-04-13 02:00:00', 'value': 201.85, 'zone': 'es'}
{'local_timestamp': '2022-04-13 05:00:00', 'utc_timestamp': '2022-04-13 03:00:00', 'value': 190.9, 'zone': 'es'}
{'local_timestamp': '2022-04-13 06:00:00', 'utc_timestamp': '2022-04-13 04:00:00', 'value': 212.32, 'zone': 'es'}
{'local_timestamp': '2022-04-13 07:00:00', 'utc_timestamp': '2022-04-13 05:00:00', 'value': 248.74, 'zone': 'es'}
{'local_timestamp': '2022-04-13 08:00:00', 'utc_timestamp': '2022-04-13 06:00:00', 'value': 257.02, 'zone': 'es'}
{'local_timestamp': '2022-04-13 09:00:00', 'utc_timestamp': '2022-04-13 07:00:00', 'value': 260.0, 'zone': 'es'}
{'local_timestamp': '2022-04-13 10:00:00', 'utc_timestamp': '2022-04-13 08:00:00', 'value': 254.25, 'zone': 'es'}
{'local_timestamp': '2022-04-13 11:00:00', 'utc_timestamp': '2022-04-13 09:00:00', 'value': 242.75, 'zone': 'es'}
{'local_timestamp': '2022-04-13 12:00:00', 'utc_timestamp': '2022-04-13 10:00:00', 'value': 234.99, 'zone': 'es'}
{'local_timestamp': '2022-04-13 13:00:00', 'utc_timestamp': '2022-04-13 11:00:00', 'value': 227.67, 'zone': 'es'}
{'local_timestamp': '2022-04-13 14:00:00', 'utc_timestamp': '2022-04-13 12:00:00', 'value': 208.0, 'zone': 'es'}
{'local_timestamp': '2022-04-13 15:00:00', 'utc_timestamp': '2022-04-13 13:00:00', 'value': 201.18, 'zone': 'es'}
{'local_timestamp': '2022-04-13 16:00:00', 'utc_timestamp': '2022-04-13 14:00:00', 'value': 196.0, 'zone': 'es'}
{'local_timestamp': '2022-04-13 17:00:00', 'utc_timestamp': '2022-04-13 15:00:00', 'value': 200.47, 'zone': 'es'}
{'local_timestamp': '2022-04-13 18:00:00', 'utc_timestamp': '2022-04-13 16:00:00', 'value': 221.2, 'zone': 'es'}
{'local_timestamp': '2022-04-13 19:00:00', 'utc_timestamp': '2022-04-13 17:00:00', 'value': 219.28, 'zone': 'es'}
{'local_timestamp': '2022-04-13 20:00:00', 'utc_timestamp': '2022-04-13 18:00:00', 'value': 242.36, 'zone': 'es'}
{'local_timestamp': '2022-04-13 21:00:00', 'utc_timestamp': '2022-04-13 19:00:00', 'value': 254.0, 'zone': 'es'}
{'local_timestamp': '2022-04-13 22:00:00', 'utc_timestamp': '2022-04-13 20:00:00', 'value': 259.0, 'zone': 'es'}
{'local_timestamp': '2022-04-13 23:00:00', 'utc_timestamp': '2022-04-13 21:00:00', 'value': 250.0, 'zone': 'es'}
{'local_timestamp': '2022-04-14 00:00:00', 'utc_timestamp': '2022-04-13 22:00:00', 'value': 231.94, 'zone': 'es'}
```

- Descargar `Precio horario de ajuste a los consumidores en el mercado`
Expand All @@ -64,28 +64,79 @@ print(*prices, sep='\n')

# Resultado
```
{'local_timestamp': '2022-06-15 01:00:00', 'utc_timestamp': '2022-06-14 23:00:00', 'value': 65.22}
{'local_timestamp': '2022-06-15 02:00:00', 'utc_timestamp': '2022-06-15 00:00:00', 'value': 71.27}
{'local_timestamp': '2022-06-15 03:00:00', 'utc_timestamp': '2022-06-15 01:00:00', 'value': 75.24}
{'local_timestamp': '2022-06-15 04:00:00', 'utc_timestamp': '2022-06-15 02:00:00', 'value': 79.33}
{'local_timestamp': '2022-06-15 05:00:00', 'utc_timestamp': '2022-06-15 03:00:00', 'value': 79.33}
{'local_timestamp': '2022-06-15 06:00:00', 'utc_timestamp': '2022-06-15 04:00:00', 'value': 80.71}
{'local_timestamp': '2022-06-15 07:00:00', 'utc_timestamp': '2022-06-15 05:00:00', 'value': 79.0}
{'local_timestamp': '2022-06-15 08:00:00', 'utc_timestamp': '2022-06-15 06:00:00', 'value': 70.84}
{'local_timestamp': '2022-06-15 09:00:00', 'utc_timestamp': '2022-06-15 07:00:00', 'value': 61.46}
{'local_timestamp': '2022-06-15 10:00:00', 'utc_timestamp': '2022-06-15 08:00:00', 'value': 56.1}
{'local_timestamp': '2022-06-15 11:00:00', 'utc_timestamp': '2022-06-15 09:00:00', 'value': 52.13}
{'local_timestamp': '2022-06-15 12:00:00', 'utc_timestamp': '2022-06-15 10:00:00', 'value': 48.45}
{'local_timestamp': '2022-06-15 13:00:00', 'utc_timestamp': '2022-06-15 11:00:00', 'value': 46.2}
{'local_timestamp': '2022-06-15 14:00:00', 'utc_timestamp': '2022-06-15 12:00:00', 'value': 45.5}
{'local_timestamp': '2022-06-15 15:00:00', 'utc_timestamp': '2022-06-15 13:00:00', 'value': 44.08}
{'local_timestamp': '2022-06-15 16:00:00', 'utc_timestamp': '2022-06-15 14:00:00', 'value': 44.82}
{'local_timestamp': '2022-06-15 17:00:00', 'utc_timestamp': '2022-06-15 15:00:00', 'value': 46.32}
{'local_timestamp': '2022-06-15 18:00:00', 'utc_timestamp': '2022-06-15 16:00:00', 'value': 48.12}
{'local_timestamp': '2022-06-15 19:00:00', 'utc_timestamp': '2022-06-15 17:00:00', 'value': 50.7}
{'local_timestamp': '2022-06-15 20:00:00', 'utc_timestamp': '2022-06-15 18:00:00', 'value': 53.55}
{'local_timestamp': '2022-06-15 21:00:00', 'utc_timestamp': '2022-06-15 19:00:00', 'value': 55.4}
{'local_timestamp': '2022-06-15 22:00:00', 'utc_timestamp': '2022-06-15 20:00:00', 'value': 56.44}
{'local_timestamp': '2022-06-15 23:00:00', 'utc_timestamp': '2022-06-15 21:00:00', 'value': 57.79}
{'local_timestamp': '2022-06-16 00:00:00', 'utc_timestamp': '2022-06-15 22:00:00', 'value': 64.2}
{'local_timestamp': '2022-06-15 01:00:00', 'utc_timestamp': '2022-06-14 23:00:00', 'value': 65.22, 'zone': 'es'}
{'local_timestamp': '2022-06-15 02:00:00', 'utc_timestamp': '2022-06-15 00:00:00', 'value': 71.27, 'zone': 'es'}
{'local_timestamp': '2022-06-15 03:00:00', 'utc_timestamp': '2022-06-15 01:00:00', 'value': 75.24, 'zone': 'es'}
{'local_timestamp': '2022-06-15 04:00:00', 'utc_timestamp': '2022-06-15 02:00:00', 'value': 79.33, 'zone': 'es'}
{'local_timestamp': '2022-06-15 05:00:00', 'utc_timestamp': '2022-06-15 03:00:00', 'value': 79.33, 'zone': 'es'}
{'local_timestamp': '2022-06-15 06:00:00', 'utc_timestamp': '2022-06-15 04:00:00', 'value': 80.71, 'zone': 'es'}
{'local_timestamp': '2022-06-15 07:00:00', 'utc_timestamp': '2022-06-15 05:00:00', 'value': 79.0, 'zone': 'es'}
{'local_timestamp': '2022-06-15 08:00:00', 'utc_timestamp': '2022-06-15 06:00:00', 'value': 70.84, 'zone': 'es'}
{'local_timestamp': '2022-06-15 09:00:00', 'utc_timestamp': '2022-06-15 07:00:00', 'value': 61.46, 'zone': 'es'}
{'local_timestamp': '2022-06-15 10:00:00', 'utc_timestamp': '2022-06-15 08:00:00', 'value': 56.1, 'zone': 'es'}
{'local_timestamp': '2022-06-15 11:00:00', 'utc_timestamp': '2022-06-15 09:00:00', 'value': 52.13, 'zone': 'es'}
{'local_timestamp': '2022-06-15 12:00:00', 'utc_timestamp': '2022-06-15 10:00:00', 'value': 48.45, 'zone': 'es'}
{'local_timestamp': '2022-06-15 13:00:00', 'utc_timestamp': '2022-06-15 11:00:00', 'value': 46.2, 'zone': 'es'}
{'local_timestamp': '2022-06-15 14:00:00', 'utc_timestamp': '2022-06-15 12:00:00', 'value': 45.5, 'zone': 'es'}
{'local_timestamp': '2022-06-15 15:00:00', 'utc_timestamp': '2022-06-15 13:00:00', 'value': 44.08, 'zone': 'es'}
{'local_timestamp': '2022-06-15 16:00:00', 'utc_timestamp': '2022-06-15 14:00:00', 'value': 44.82, 'zone': 'es'}
{'local_timestamp': '2022-06-15 17:00:00', 'utc_timestamp': '2022-06-15 15:00:00', 'value': 46.32, 'zone': 'es'}
{'local_timestamp': '2022-06-15 18:00:00', 'utc_timestamp': '2022-06-15 16:00:00', 'value': 48.12, 'zone': 'es'}
{'local_timestamp': '2022-06-15 19:00:00', 'utc_timestamp': '2022-06-15 17:00:00', 'value': 50.7, 'zone': 'es'}
{'local_timestamp': '2022-06-15 20:00:00', 'utc_timestamp': '2022-06-15 18:00:00', 'value': 53.55, 'zone': 'es'}
{'local_timestamp': '2022-06-15 21:00:00', 'utc_timestamp': '2022-06-15 19:00:00', 'value': 55.4, 'zone': 'es'}
{'local_timestamp': '2022-06-15 22:00:00', 'utc_timestamp': '2022-06-15 20:00:00', 'value': 56.44, 'zone': 'es'}
{'local_timestamp': '2022-06-15 23:00:00', 'utc_timestamp': '2022-06-15 21:00:00', 'value': 57.79, 'zone': 'es'}
{'local_timestamp': '2022-06-16 00:00:00', 'utc_timestamp': '2022-06-15 22:00:00', 'value': 64.2, 'zone': 'es'}
```

- Descargar `Precio marginal de compra de MIBGAS`

```python
from datetime import datetime
from guess_omie_price.mibgas_getter import download_pmc_on_date

d = datetime(2022, 6, 15)
prices = download_pmc_on_date(d)

print(*prices, sep='\n')
```

# Resultado
```
# Prices are ordered descending
{'value': 52.7, 'local_timestamp': '2022-01-01 00:00:00', 'utc_timestamp': '2021-12-31 23:00:00', 'zone': 'es'}
{'value': 56.25, 'local_timestamp': '2022-01-02 00:00:00', 'utc_timestamp': '2022-01-01 23:00:00', 'zone': 'es'}
{'value': 79.0, 'local_timestamp': '2022-01-03 00:00:00', 'utc_timestamp': '2022-01-02 23:00:00', 'zone': 'es'}
{'value': 81.72, 'local_timestamp': '2022-01-04 00:00:00', 'utc_timestamp': '2022-01-03 23:00:00', 'zone': 'es'}
{'value': 91.54, 'local_timestamp': '2022-01-05 00:00:00', 'utc_timestamp': '2022-01-04 23:00:00', 'zone': 'es'}
{'value': 95.8, 'local_timestamp': '2022-01-06 00:00:00', 'utc_timestamp': '2022-01-05 23:00:00', 'zone': 'es'}
{'value': 94.67, 'local_timestamp': '2022-01-07 00:00:00', 'utc_timestamp': '2022-01-06 23:00:00', 'zone': 'es'}
{'value': 89.06, 'local_timestamp': '2022-01-08 00:00:00', 'utc_timestamp': '2022-01-07 23:00:00', 'zone': 'es'}
{'value': 88.17, 'local_timestamp': '2022-01-09 00:00:00', 'utc_timestamp': '2022-01-08 23:00:00', 'zone': 'es'}
{'value': 89.43, 'local_timestamp': '2022-01-10 00:00:00', 'utc_timestamp': '2022-01-09 23:00:00', 'zone': 'es'}
{'value': 87.09, 'local_timestamp': '2022-01-11 00:00:00', 'utc_timestamp': '2022-01-10 23:00:00', 'zone': 'es'}
{'value': 82.43, 'local_timestamp': '2022-01-12 00:00:00', 'utc_timestamp': '2022-01-11 23:00:00', 'zone': 'es'}
{'value': 79.02, 'local_timestamp': '2022-01-13 00:00:00', 'utc_timestamp': '2022-01-12 23:00:00', 'zone': 'es'}
{'value': 92.5, 'local_timestamp': '2022-01-14 00:00:00', 'utc_timestamp': '2022-01-13 23:00:00', 'zone': 'es'}
{'value': 91.33, 'local_timestamp': '2022-01-15 00:00:00', 'utc_timestamp': '2022-01-14 23:00:00', 'zone': 'es'}
{'value': 93.55, 'local_timestamp': '2022-01-16 00:00:00', 'utc_timestamp': '2022-01-15 23:00:00', 'zone': 'es'}
{'value': 88.72, 'local_timestamp': '2022-01-17 00:00:00', 'utc_timestamp': '2022-01-16 23:00:00', 'zone': 'es'}
{'value': 82.57, 'local_timestamp': '2022-01-18 00:00:00', 'utc_timestamp': '2022-01-17 23:00:00', 'zone': 'es'}
{'value': 78.53, 'local_timestamp': '2022-01-19 00:00:00', 'utc_timestamp': '2022-01-18 23:00:00', 'zone': 'es'}
{'value': 74.89, 'local_timestamp': '2022-01-20 00:00:00', 'utc_timestamp': '2022-01-19 23:00:00', 'zone': 'es'}
{'value': 76.11, 'local_timestamp': '2022-01-21 00:00:00', 'utc_timestamp': '2022-01-20 23:00:00', 'zone': 'es'}
{'value': 82.38, 'local_timestamp': '2022-01-22 00:00:00', 'utc_timestamp': '2022-01-21 23:00:00', 'zone': 'es'}
{'value': 85.75, 'local_timestamp': '2022-01-23 00:00:00', 'utc_timestamp': '2022-01-22 23:00:00', 'zone': 'es'}
{'value': 89.19, 'local_timestamp': '2022-01-24 00:00:00', 'utc_timestamp': '2022-01-23 23:00:00', 'zone': 'es'}
{'value': 91.24, 'local_timestamp': '2022-01-25 00:00:00', 'utc_timestamp': '2022-01-24 23:00:00', 'zone': 'es'}
{'value': 93.3, 'local_timestamp': '2022-01-26 00:00:00', 'utc_timestamp': '2022-01-25 23:00:00', 'zone': 'es'}
{'value': 93.03, 'local_timestamp': '2022-01-27 00:00:00', 'utc_timestamp': '2022-01-26 23:00:00', 'zone': 'es'}
{'value': 93.53, 'local_timestamp': '2022-01-28 00:00:00', 'utc_timestamp': '2022-01-27 23:00:00', 'zone': 'es'}
{'value': 94.99, 'local_timestamp': '2022-01-29 00:00:00', 'utc_timestamp': '2022-01-28 23:00:00', 'zone': 'es'}
{'value': 96.47, 'local_timestamp': '2022-01-30 00:00:00', 'utc_timestamp': '2022-01-29 23:00:00', 'zone': 'es'}
{'value': 89.38, 'local_timestamp': '2022-01-31 00:00:00', 'utc_timestamp': '2022-01-30 23:00:00', 'zone': 'es'}
{'value': 81.67, 'local_timestamp': '2022-02-01 00:00:00', 'utc_timestamp': '2022-01-31 23:00:00', 'zone': 'es'}
...
# Note: File continues till last publish price for specified year
```
35 changes: 35 additions & 0 deletions guess_omie_price/mibgas_getter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
from guess_omie_price.utils import download_mibgas_component_on_date
import logging
import zipfile


def download_pmc_on_date(today, zone='es'):
"""
Downloads PMC data from MIBGAS
:param today: datetime
:param zone: str, must be in ('es', 'pt')
:return: list of dict
"""
logger = logging.getLogger('MIBGAS')
logger.info(f'Descargando precios PMC para la fecha {today}.')

year = today.year

if year < 2019:
sheet_number = 6
else:
sheet_number = 7

try:
base_url = f'https://www.mibgas.es/es/file-access/'
file_url = f'MIBGAS_Data_{year}.xlsx?path=AGNO_{year}/XLS'

return download_mibgas_component_on_date(base_url, file_url, sheet_number, zone=zone)

except IndexError:
logger.info(f'No se han podido descargar los precios PMC en fecha {today}.')
return []
except zipfile.BadZipFile:
logger.info(f'No se han podido descargar los precios PMC en fecha {today}.')
return []
38 changes: 37 additions & 1 deletion guess_omie_price/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from datetime import timedelta
from guess_omie_price.headers import ZONE_MAP
from io import StringIO
from io import StringIO, BytesIO
from pytz import timezone
import pandas as pd
import requests
Expand Down Expand Up @@ -40,8 +40,44 @@ def download_omie_component_on_date(today, base_url, file_url, file_header, zone
register['local_timestamp'] = local_timestamp.strftime('%Y-%m-%d %H:%M:%S')
register['utc_timestamp'] = utc_timestamp.strftime('%Y-%m-%d %H:%M:%S')
register['value'] = val
register['zone'] = zone.lower()

res.append(register)
current_utc_timestamp += timedelta(hours=1)

return res


def download_mibgas_component_on_date(base_url, file_url, sheet_number, zone):
"""
Downloads component data from MIBGAS
:param base_url: str
:param file_url: str
:param sheet_number: int
:param zone: str, must be in ('es', 'pt')
:return: list of dict
"""
url = base_url + file_url
r = requests.get(url)
io = BytesIO(r.content)

column = pd.read_excel(io, sheet_name=sheet_number, usecols=[0, 1, 5], engine='openpyxl')
column.rename(columns={'Marginal purchase price\n[EUR/MWh]': 'value'}, inplace=True)

data = column.T.to_dict().values()

res = []
for register in data:
if register['Zone'] != zone.upper():
continue
local_timestamp = LOCAL_TZ.localize(register['Date'], '%Y-%m-%d %H:%M:%S')
utc_timestamp = UTC_TZ.normalize(local_timestamp.astimezone(UTC_TZ))
register.pop('Date')
register.pop('Zone')
register['local_timestamp'] = local_timestamp.strftime('%Y-%m-%d %H:%M:%S')
register['utc_timestamp'] = utc_timestamp.strftime('%Y-%m-%d %H:%M:%S')
register['zone'] = zone.lower()

res = [register] + res

return res
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
openpyxl
pandas
pytz
requests
38 changes: 38 additions & 0 deletions spec/mibgas_better_spec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
from datetime import datetime, timedelta
from guess_omie_price.mibgas_getter import download_pmc_on_date
from mamba import context, description, it

with description('PMC'):
with context('PMC getter'):
with it('Downloads prices for a valid datetime'):
d = datetime(2022, 7, 16)
prices = download_pmc_on_date(d)

res_prices = [x['value'] for x in prices]

expected_price = 106.66
assert res_prices[197-1] == expected_price # 2022-07-16 is the year number 197 on 2022

with it('Does not fail execution for an invalid datetime'):
d = datetime.today() + timedelta(days=365) # next year must not be published yet
prices = download_pmc_on_date(d)
assert len(prices) == 0
assert prices == []

with it('Downloads prices for specified zone (Spain by default)'):
d = datetime(2022, 7, 16)
prices = download_pmc_on_date(d)

res_prices = [x['value'] for x in prices]

expected_price = 106.66
assert res_prices[197-1] == expected_price # 2022-07-16 is the year number 197 on 2022

d = datetime(2022, 7, 16)
prices = download_pmc_on_date(d, 'pt')

res_prices = [x['value'] for x in prices]

expected_price = 108.20
assert res_prices[197-1] == expected_price # 2022-07-16 is the year number 197 on 2022

0 comments on commit fb9e2c6

Please sign in to comment.