Garbage pickup date (mijnafvalwijzer.nl) custom_component

This looks great and is a good start. Unfortunately the city I live in uses slightly different codes for the various of garbage collections (one of which breaks the code).

For my installation I had to add the following trash types:

TRASH_TYPES = [{1: "gft"}, {2: "pmd"}, {3: "papier"}, {4: "restafval"}, {5: "restgft"}, {6: "plastic"}]

Due to some incompatible nameType’s in the JSON I also had to change to the type property, see code below:

        for name in TRASH_TYPES:
            for item in json_obj['data']['ophaaldagen']['data'] or json_obj['data']['ophaaldagenNext']['data']:
                if item['date'] > today:
                    if item['type'] in name.values():
                        trash = {}
                        #trash['shortcode'] = (next(iter(name.values())))
                        trash['name_type'] = item['type']
                        trash['pickup_date'] = (str(datetime.datetime.strptime(item['date'], "%Y-%m-%d")))
                        #trash['pickup_date'] = (str(datetime.datetime.strptime(item['date'], "%Y-%m-%d") + datetime.timedelta(days=0)))
                        tschedule.append(trash)
                        self.data = tschedule
                        break

This was caused by the following JSON:

{
        "nameType": "rest\/gft",
	"type": "restgft",
	"date": "2018-01-22"
}, {
	"nameType": "plastic ",
	"type": "plastic",
	"date": "2018-01-29"
}
2 Likes