From 06450d93c672c04adc2e1a872e88d2972c5db3cf Mon Sep 17 00:00:00 2001 From: Bram van Dartel Date: Mon, 4 Feb 2019 11:50:46 +0100 Subject: [PATCH] add firstdate and firstwastetype --- custom_components/sensor/mijnafvalwijzer.py | 24 ++++++++++++------- .../mijnafvalwijzer_scraper.py | 2 ++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/custom_components/sensor/mijnafvalwijzer.py b/custom_components/sensor/mijnafvalwijzer.py index 19253e0..ec2443a 100644 --- a/custom_components/sensor/mijnafvalwijzer.py +++ b/custom_components/sensor/mijnafvalwijzer.py @@ -1,6 +1,6 @@ """ @ Authors : Bram van Dartel -@ Date : 17/01/2019 +@ Date : 04/02/2019 @ Description : MijnAfvalwijzer Scrape Sensor - It queries mijnafvalwijzer.nl. sensor: @@ -11,7 +11,7 @@ label_geen: 'Geen' """ -VERSION = '2.0.5' +VERSION = '2.0.6' import itertools import logging @@ -73,7 +73,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): # Get trash shortname trashShortNames = [] uniqueTrashShortNames = [] - defaultTrashNames = ['today', 'tomorrow', 'next'] + defaultTrashNames = ['firstdate', 'firstwastetype', 'today', 'tomorrow', 'next'] uniqueTrashShortNames.extend(defaultTrashNames) sensors = [] try: @@ -245,7 +245,6 @@ def _get_month_number(month): except IndexError: return 'Error, empty reply.' - # Append first upcoming unique trash item with pickup date uniqueTrashNames = [] uniqueTrashNames.extend(self.defaultTrashNames) @@ -267,8 +266,7 @@ def _get_month_number(month): except IndexError: return 'Error, empty reply.' - - # Collect data + # Collect data for today, tomorrow and next today_out = [x for x in trashSchedule if datetime.strptime(x['value'], "%d-%m-%Y") == today_date] logger.debug(f"Trash Today: {today_out}") tomorrow_out = [x for x in trashSchedule if datetime.strptime(x['value'], "%d-%m-%Y") == tomorrow_date] @@ -297,7 +295,6 @@ def _get_month_number(month): except IndexError: return 'Error, empty reply.' - # Append Tomorrow data trashTomorrow = {} multiTrashTomorrow = [] @@ -319,7 +316,6 @@ def _get_month_number(month): except IndexError: return 'Error, empty reply.' - # Append next pickup in days trashNext = {} ## Amount of days between two dates function @@ -341,6 +337,18 @@ def days(start, end): trashSchedule.append(trashNext) logger.debug(f"Next data succesfully added {trashNext}") + # Append firstDate and firstWasteType + trashFirstDate = {} + trashFirstDate['key'] = 'firstdate' + trashFirstDate['value'] = soup.find('p', attrs={'class':'firstDate'}).text + trashSchedule.append(trashFirstDate) + logger.debug(f"firstDate data succesfully added {trashFirstDate}") + + firstWasteType = {} + firstWasteType['key'] = 'firstwastetype' + firstWasteType['value'] = soup.find('p', attrs={'class':'firstWasteType'}).text + trashSchedule.append(firstWasteType) + logger.debug(f"firstDate data succesfully added {firstWasteType}") # Return collected data logger.debug(f"trashSchedule content {trashSchedule}") diff --git a/standalone_python_scraper/mijnafvalwijzer_scraper.py b/standalone_python_scraper/mijnafvalwijzer_scraper.py index a674ad5..b3206fe 100644 --- a/standalone_python_scraper/mijnafvalwijzer_scraper.py +++ b/standalone_python_scraper/mijnafvalwijzer_scraper.py @@ -26,6 +26,8 @@ def scraper(url, trash=None): year_id = item["id"] year = re.sub('jaar-','',year_id) + #print("test", soup.find('div', attrs={'class':'ophaaldagen'}).text) + # Get trash date try: for data in soup.select('a[href*="#waste"] p[class]'):