def get_currency(self, currency_name="USD", date=None): """Get currency data for the given currency name""" today = datetime.date.today() if date is None: date = today if currency_name.upper() not in self.allowed_currencies: allowed = ", ".join(self.allowed_currencies) msg = "Incorrect currency '{}', allowed values: {}" raise BotLoggedError(msg.format(currency_name, allowed)) currencies = self.get_all_currencies(date=date) for currency in currencies: if currency.iso.upper() == currency_name: return currency return Currency.empty_currency()
def get_currency(self, currency_name: str = "USD", date: datetime.date = None) -> Currency: logger.info("Belgazprom: getting {}" "for the {}".format(currency_name, date)) today = datetime.date.today() if date is None: date = today assert isinstance(date, datetime.date), "Incorrect date supplied" currencies = self.get_all_currencies(date) for cur in currencies: if currency_name.upper() == cur.iso: return cur else: return Currency.empty_currency()
def get_currency(self, currency_name: str="USD", date: datetime.date=None) -> Currency: logger.info("Belgazprom: getting {}" "for the {}".format(currency_name, date)) today = datetime.date.today() if date is None: date = today assert isinstance(date, datetime.date), "Incorrect date supplied" currencies = self.get_all_currencies(date) for cur in currencies: if currency_name.upper() == cur.iso: return cur else: return Currency.empty_currency()
def get_currency(self, currency_name="USD", date=None): """Get currency data for the given currency name""" today = datetime.date.today() if date is None: date = today if currency_name.upper() not in PriorbankParser.allowed_currencies: allowed = ", ".join(PriorbankParser.allowed_currencies) msg = "Incorrect currency '{}', allowed values: {}" raise BotLoggedError(msg.format(currency_name, allowed)) currencies = self.get_all_currencies(date=date) for currency in currencies: if currency.iso.upper() == currency_name: if date < DENOMINATION_DATE: currency.multiplier = DENOMINATION_MULTIPLIER else: currency.multiplier = 1 return currency return Currency.empty_currency()
def __get_currency_objects(self, cur_table: BeautifulSoup, days_since_now=None) -> Sequence[Currency]: """ Parses BeautifulSoup table with exchanges rates and extracts currency data """ if not days_since_now: currencies = [] exchange_table = cur_table.find('table').find('tbody') exchange_rows = exchange_table.find_all('tr') for row in exchange_rows: try: c = BelgazpromParser.__currency_object_from_row(row) currencies.append(c) except ValueError: logger.error("Error obtaining currency object from {}".format(row)) currencies.append(Currency.empty_currency()) return currencies
def __get_currency_objects(self, cur_table: BeautifulSoup, days_since_now=None) -> Sequence[Currency]: """ Parses BeautifulSoup table with exchanges rates and extracts currency data """ if not days_since_now: currencies = [] exchange_table = cur_table.find('table').find('tbody') exchange_rows = exchange_table.find_all('tr') for row in exchange_rows: try: c = BelgazpromParser.__currency_object_from_row(row) currencies.append(c) except ValueError: logger.error( "Error obtaining currency object from {}".format(row)) currencies.append(Currency.empty_currency()) return currencies