Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions homeassistant/components/sensor/geizhals.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,21 @@ def update(self):
timeout=1)
soup = bs4.BeautifulSoup(request.text, 'html.parser')

# parse name
raw = soup.find_all('span', attrs={'itemprop': 'name'})
self.device_name = raw[1].string
# Parse name
raw = soup.find('h1', attrs={'class': 'gh-headline'})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be extracted from Home Assistant and into a separate Python library. We will not be able to accept any changes to this platform until this is fixed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your comments @MartinHjelmare and @balloob ! I will create a separate library for that.

self.device_name = raw.string

# parse prices
# Parse prices
prices = []
for tmp in soup.find_all('span', attrs={'class': 'gh_price'}):
for tmp in soup.select('div.offer__price .gh_price'):
matches = re.search(self.regex, tmp.string)
raw = '{}.{}'.format(matches.group(1),
matches.group(2))
prices += [float(raw)]
prices.sort()
self.prices = prices[1:]

# parse unit
# Parse unit
price_match = soup.find('span', attrs={'class': 'gh_price'})
matches = re.search(r'€|£|PLN', price_match.string)
self.unit_of_measurement = matches.group()