⚠️Time to BinReal.⚠️

⚠️Time to BinReal.⚠️

18/12/2022

When moving into my new student house, my housemate had the idea to create a bin reminder. Not a difficult project, but one that we decided to do right.

The plan was to build a program to scrape and parse the council’s bin website. As our other housemates point out, we could just enter a weekly reminder into out calendar but that would be silly.

The coucil website consisted of a form that we had to populate using a series of GET and PULL requests. The site is built using the .NET framework and which makes it slightly challending to work with since there are cookies required:

payload1['__VIEWSTATE'] = soup1.select_one("#__VIEWSTATE")['value']
payload1['__VIEWSTATEGENERATOR'] = soup1.select_one("#__VIEWSTATEGENERATOR")['value']
payload1['__EVENTVALIDATION'] = soup1.select_one("#__EVENTVALIDATION")['value']

Any sensitive data is stored in a .env file such as address and API keys for the notifications.

Push Notifications

A key part of the project was to create a dedicated push notification. We didn’t want an email or text since they can seem like spam. I found a website called PushSafer which provides the framework for the push notifications.

We registered our devices with my account and all it takes is an API call to send a message. We created a developer group with is a subgroup of the devices that receive a message when something has gone wrong.

url = 'https://www.pushsafer.com/api'
post_fields = {
  "t" : title,
  "m" : message,
  "v" : 3,
  "i" : icon,
  "d" : group,
  "k" : private_key, 
}

Bindicator Notification

Cron Job

The program runs every day at 7pm and only sends a notification to everyone’s device if there is a bin to be taken out the next day. The developer group receives a notification every day to validate that the site is still working.

I have a shared hosting server that we uploaded the program to.

We then created the cron job to execute the program on the given schedule:

0 19 * * * python bindicator.py

So far we have had a 100% success rate with taking out the bins 🗑️:)