Skip to content

Commit

Permalink
add firstdate and firstwastetype
Browse files Browse the repository at this point in the history
  • Loading branch information
xirixiz committed Feb 4, 2019
1 parent da46c7c commit 06450d9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
24 changes: 16 additions & 8 deletions custom_components/sensor/mijnafvalwijzer.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -11,7 +11,7 @@
label_geen: 'Geen'
"""

VERSION = '2.0.5'
VERSION = '2.0.6'

import itertools
import logging
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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]
Expand Down Expand Up @@ -297,7 +295,6 @@ def _get_month_number(month):
except IndexError:
return 'Error, empty reply.'


# Append Tomorrow data
trashTomorrow = {}
multiTrashTomorrow = []
Expand All @@ -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
Expand All @@ -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}")
Expand Down
2 changes: 2 additions & 0 deletions standalone_python_scraper/mijnafvalwijzer_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]'):
Expand Down

0 comments on commit 06450d9

Please sign in to comment.