Skip to content

Commit

Permalink
#56 handle case of missing official nl date
Browse files Browse the repository at this point in the history
  • Loading branch information
myTselection committed Sep 7, 2024
1 parent 17869c1 commit 6fc32e5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion custom_components/carbu_com/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/myTselection/carbu_com/issues",
"requirements": ["bs4","requests","voluptuous", "ratelimit"],
"version": "11.2.1"
"version": "11.2.2"
}
5 changes: 3 additions & 2 deletions custom_components/carbu_com/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,7 @@ def getFuelOfficialNl(self, fueltype: FuelType, country):

soup = BeautifulSoup(response.text, 'html.parser')

date_text = None
for paragraph in soup.find_all('p', class_='text-xs'):
if paragraph.text.strip().startswith("Datum overzicht"):
date_text = paragraph.text.replace("Datum overzicht ", "").strip()
Expand Down Expand Up @@ -924,7 +925,7 @@ def translate_month(dutch_date_str):
return f"{spaceSplit[0]} {month_translation.get(spaceSplit[1], spaceSplit[1])} {spaceSplit[2]}"

# Convert the date text to a datetime.date object if found
date_object = None
date_object = date.today()
if date_text:
try:
# Translate Dutch month to English
Expand All @@ -933,7 +934,7 @@ def translate_month(dutch_date_str):
date_object = datetime.strptime(translated_date_text, "%d %B %Y").date()
except ValueError:
# Handle cases where the date format is unexpected or incorrect
date_object = None
date_object = date.today()

# Assuming 'soup' is the BeautifulSoup object containing your HTML
data = {}
Expand Down

0 comments on commit 6fc32e5

Please sign in to comment.