Skip to content

Commit

Permalink
add property
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcDirven committed Mar 30, 2024
1 parent 226bc70 commit 7a8e2e1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
5 changes: 0 additions & 5 deletions vrijopnaam_prices/_parse_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,3 @@ def get_start_end(s: str) -> Tuple[int, int]:

def get_price(record: bs4.BeautifulSoup) -> float:
return make_float(remove_whitespace(record.text))


def to_pascal_case(name: str) -> str:
components = name.split('_')
return ''.join(components[0].lower() + ''.join(x.title() for x in components[1:]))
18 changes: 9 additions & 9 deletions vrijopnaam_prices/dynamic_price.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ def __init__(self, cur: str, unit: str, table: bs4.BeautifulSoup, price_type: st
self._table = table
self.__type = price_type

def __get_currency(self) -> str:
@property
def currency(self) -> str:
return self.__currency

def __get_unit(self) -> str:
@property
def unit(self) -> str:
return self.__unit

def __get_type(self) -> str:
@property
def type(self) -> str:
return self.__type

def get_prices(self) -> Iterable[TimeBoundedPrice]:
pass
@property
def prices(self) -> Iterable[TimeBoundedPrice]:
raise

def to_json(self):
pass

type = property(fget=__get_type)
currency = property(fget=__get_currency)
unit = property(fget=__get_unit)
10 changes: 6 additions & 4 deletions vrijopnaam_prices/dynamic_prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def __init__(self, table: bs4.BeautifulSoup):
cur, unit = pu.get_units(pu.remove_whitespace(table.find_all('th')[1].text))
super().__init__(cur, unit, table, 'gas')

def get_prices(self) -> Iterable[TimeBoundedPrice]:
@property
def prices(self) -> Iterable[TimeBoundedPrice]:
body = self._table.find('tbody')
all_tr = body.find_all('tr')
pricing_today = pu.make_float(pu.remove_whitespace(all_tr[0].find_all('td')[2].text))
Expand All @@ -49,7 +50,7 @@ def get_prices(self) -> Iterable[TimeBoundedPrice]:
yield TimeBoundedPrice(start_yesterday, start_today, pricing_yesterday)

def to_json(self) -> dict[str, Any]:
return _make_prices_json(self.currency, self.unit, (price.to_json() for price in self.get_prices()))
return _make_prices_json(self.currency, self.unit, (price.to_json() for price in self.prices))


class DynamicElectricityPrices(DynamicPrice):
Expand All @@ -64,7 +65,8 @@ def __init__(self, table: bs4.BeautifulSoup):
self.__day_left = pu.get_day(left)
self.__day_right = pu.get_day(right)

def get_prices(self) -> Iterable[TimeBoundedPrice]:
@property
def prices(self) -> Iterable[TimeBoundedPrice]:
body = self._table.find('tbody').find_all('tr')
for record in body:
period, price_left, price_right = record.find_all('td')
Expand All @@ -86,7 +88,7 @@ def get_prices(self) -> Iterable[TimeBoundedPrice]:
yield TimeBoundedPrice(start_hour_right.replace(hour=start), end_hour_right, price_right)

def to_json(self) -> dict[str, Any]:
return _make_prices_json(self.currency, self.unit, (price.to_json() for price in self.get_prices()))
return _make_prices_json(self.currency, self.unit, (price.to_json() for price in self.prices))


class DynamicPrices:
Expand Down

0 comments on commit 7a8e2e1

Please sign in to comment.