Skip to content

Commit

Permalink
Fix Poalim USD currency name
Browse files Browse the repository at this point in the history
  • Loading branch information
jond01 committed Oct 28, 2024
1 parent 4c0a082 commit 2d467d6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 3 additions & 1 deletion xil/_currencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ class CurrencyCode(StrEnum):
XPT = "XPT" # Platinum


USD_HEB_NAME = 'דולר ארה"ב'

_HEB_CURRENCY_NAME_TO_CODE: dict[str, CurrencyCode] = {
"שקל חדש": CurrencyCode.ILS,
'דולר ארה"ב': CurrencyCode.USD,
USD_HEB_NAME: CurrencyCode.USD,
"לירה שטרלינג": CurrencyCode.GBP,
'ליש"ט': CurrencyCode.GBP,
'ליש"ט בריטי': CurrencyCode.GBP,
Expand Down
21 changes: 20 additions & 1 deletion xil/poalim.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import pandas as pd

from xil._currencies import USD_HEB_NAME
from xil._df_normalizer import JPYNormalizer

_POALIM_GET_URL = "https://www.bankhapoalim.co.il/he/coin-rates"
Expand Down Expand Up @@ -37,6 +38,24 @@ def _get_url(t: date | None) -> str:
return _POALIM_QUERY + t.strftime(_DATE_FORMAT)


class PoalimNormalizer(JPYNormalizer):
"""Bank HaPoalim data normalizer"""

_USD_ALIAS = 'דולר ארה"ב - Cloned'

@classmethod
def _fix_usd(cls, raw_name: str) -> str:
"""Fix USD currency name"""
if raw_name == cls._USD_ALIAS:
return USD_HEB_NAME
return raw_name

@classmethod
def preprocess_names(cls, names: pd.Series) -> pd.Series:
names = super().preprocess_names(names)
return names.apply(cls._fix_usd)


def get_df(t: date | None = None, keep_last_date_only: bool = True) -> pd.DataFrame:
"""
Get poalim exchange data from the latest available day or a specified
Expand All @@ -55,5 +74,5 @@ def get_df(t: date | None = None, keep_last_date_only: bool = True) -> pd.DataFr
if keep_last_date_only and t is None:
df = df[df.date == df.date.max()]

df = JPYNormalizer(df).norm()
df = PoalimNormalizer(df).norm()
return df

0 comments on commit 2d467d6

Please sign in to comment.