Skip to content

Commit

Permalink
refactor: replace list_monitors_images with get_url_image for image r…
Browse files Browse the repository at this point in the history
…etrieval
  • Loading branch information
fcoagz committed Jan 10, 2025
1 parent af211d2 commit aa5ee3c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/services/pages/alcambio.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from ...utils.request import request
from ...utils.time import get_formatted_timestamp
from ...utils.extras import list_monitors_images
from ...utils.func_consts import get_url_image
from ..._pages import AlCambio
from ._base import Base

Expand All @@ -22,7 +22,7 @@ def _load(cls, **kwargs):
name = 'EnParaleloVzla' if not rate['official'] else 'BCV'
key = name.lower()
date = get_formatted_timestamp(country_conversions['dateParalelo'] if not rate['official'] else country_conversions['dateBcv'])
image = next((image.image for image in list_monitors_images if image.provider == 'alcambio' and image.title == key), None)
image = get_url_image(cls.PAGE.name, key)
rates.append({
'key': key,
'title': name,
Expand Down
7 changes: 4 additions & 3 deletions src/services/pages/bcv.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from bs4 import BeautifulSoup
from ...utils.request import request
from ...utils.extras import currencies, list_monitors_images, bank_dict
from ...utils.extras import currencies, bank_dict
from ...utils.time import get_formatted_date_bcv, get_datestring_to_datetime
from ...utils.func_consts import get_url_image
from ..._pages import BCV
from ._base import Base

Expand Down Expand Up @@ -32,7 +33,7 @@ def _load(cls, **kwargs):
field_tasa_venta = bank.find('td', 'views-field views-field-field-tasa-venta').text
if field_tasa_venta.count(',') == 1:
price = float(field_tasa_venta.replace(',', '.'))
image = next((image.image for image in list_monitors_images if image.provider == 'bcv' and image.title == key), None)
image = get_url_image(cls.PAGE.name, key)
last_update = get_datestring_to_datetime(bank.find('td', 'views-field views-field-field-fecha-del-indicador').text.strip().replace('-', '/'))

rates.append({
Expand All @@ -44,7 +45,7 @@ def _load(cls, **kwargs):
})

for code, values in currencies.items():
image = next((image.image for image in list_monitors_images if image.provider == 'bcv' and image.title == code), None)
image = get_url_image(cls.PAGE.name, code)
rates.append({
'key': code,
'title': values['name'],
Expand Down
5 changes: 2 additions & 3 deletions src/services/pages/criptodolar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from ...utils.request import request
from ...utils.time import get_formatted_date_tz
from ...utils.common import _convert_specific_format, _convert_dollar_name_to_monitor_name
from ...utils.extras import list_monitors_images
from ...utils.func_consts import get_url_image
from ..._pages import CriptoDolar
from ._base import Base

Expand All @@ -17,9 +17,8 @@ def _load(cls, **kwargs):

for monitor in response:
if monitor['type'] in ['bolivar', 'bancove']:
image = next((image.image for image in list_monitors_images if image.provider == 'criptodolar' and image.title == _convert_specific_format(
_convert_dollar_name_to_monitor_name(monitor['name']))), None)
key = _convert_specific_format(_convert_dollar_name_to_monitor_name(monitor['name']))
image = get_url_image(cls.PAGE.name, key)
title = _convert_dollar_name_to_monitor_name(monitor['name'])
price = round(monitor['price'], 2)
last_update = get_formatted_date_tz(monitor['updatedAt'])
Expand Down
4 changes: 2 additions & 2 deletions src/services/pages/dolartoday.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from datetime import datetime
from ...utils.request import request
from ...utils.extras import list_monitors_images
from ...utils.func_consts import get_url_image
from ...utils.common import _convert_specific_format, _convert_dollar_name_to_monitor_name
from ...utils.time import standard_time_zone
from ..._pages import DolarToday
Expand All @@ -21,7 +21,7 @@ def _load(cls, **kwargs):
for key, value in response.items():
title = _convert_dollar_name_to_monitor_name(key)
key = _convert_specific_format(title)
image = next((image.image for image in list_monitors_images if image.provider == 'dolartoday' and image.title == key), None)
image = get_url_image(cls.PAGE.name, key)
price = float(str(value).replace('Bs.', '').strip())
last_update = datetime.now(standard_time_zone)

Expand Down
4 changes: 2 additions & 2 deletions src/services/pages/enparalelovzla.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
from bs4 import BeautifulSoup
from ...utils.request import request
from ...utils.extras import list_monitors_images
from ...utils.func_consts import get_url_image
from ...utils.time import get_formatted_date
from ..._pages import EnParaleloVzla
from ._base import Base
Expand Down Expand Up @@ -37,7 +37,7 @@ def _load(cls, **kwargs):

if price is not None:
last_update = get_formatted_date(cls._get_date_message(data_message))
image = next((image.image for image in list_monitors_images if image.provider == 'enparalelovzla' and image.title == 'enparalelovzla'), None)
image = get_url_image(cls.PAGE.name, 'enparalelovzla')

data = {
'key': 'enparalelovzla',
Expand Down

0 comments on commit aa5ee3c

Please sign in to comment.