Skip to content

Commit

Permalink
Adjust rate provider to read english export from PP
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderLill committed Mar 11, 2024
1 parent 87c2305 commit 9bf755f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
3 changes: 2 additions & 1 deletion cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
if args.pp_rates_file:
rate_provider = PortfolioPerformanceRateProvider(args.pp_rates_file,
currency_mapping=args.currency_mapping,
fiat_currency=args.fiat_currency)
fiat_currency=args.fiat_currency,
language=args.language)
else:
rate_provider = None

Expand Down
2 changes: 1 addition & 1 deletion src/ledger_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self, filename=None, csv_sep=",", dataframe=None,
self._i18n = I18n(language)
# shortcuts for i18n values
self.DELIVERY_INBOUND = self._i18n.get("portfolio.DELIVERY_INBOUND")
self.BUY = self._i18n.get("portfolio.BUY")
self.BUY = self._i18n.get("account.BUY")
self.SELL = self._i18n.get("account.SELL")
self.FEES = self._i18n.get("account.FEES")

Expand Down
19 changes: 14 additions & 5 deletions src/portfolio_performance_rate_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@
import locale

class PortfolioPerformanceRateProvider:
def __init__(self, export_file, fiat_currency="EUR", time_format="%Y-%m-%d %H:%M:%S", currency_mapping=None):
def __init__(self, export_file, fiat_currency="EUR", time_format="%Y-%m-%d %H:%M:%S", language="de", currency_mapping=None):
if language == "de":
self._thousands = "."
self._decimal = ","
self._sep = ";"
if language == "en":
self._thousands = ","
self._decimal = "."
self._sep = ","
self._export_file = export_file
self._fiat_currency = fiat_currency
self._time_format = time_format
self.__df = pd.read_csv(export_file, sep=";", index_col=0, parse_dates=[0])
self.__df = pd.read_csv(export_file, sep=self._sep, index_col=0, parse_dates=[0], thousands=self._thousands, decimal=self._decimal)
if currency_mapping is not None:
self.__df.rename(columns=currency_mapping, inplace=True)
locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8') # TODO: Cleanup locale stuff
Expand All @@ -39,6 +47,7 @@ def get_rate(self, crypto_currency, timestr=None, timeobj=None):
else:
raise ValueError(f'Could not find rate for currency {column_name} in export loaded from {self._export_file}\nFound columns: ' + "\n".join(self.__df.columns))

rate = rate.replace(".", "") # Need to remove thousands-sep, locale stuff does not work ... 15.426,75

return locale.atof(rate)
# TODO: Cleanup locale stuff
# rate = rate.replace(self._thousands, "") # Need to remove thousands-sep, locale stuff does not work ... 15.426,75
# return locale.atof(rate)
return rate

0 comments on commit 9bf755f

Please sign in to comment.