Offer monitor for otomoto.pl [Service + Architecture]

Many people told me that the way I bought my car is very interesting. Therefore I decided to create a solution for everyone! Using my service you will be able to receive an email with new offers from otomoto.pl 4 times a day for 7 days.

The only limitation in place is the number of pages you get in otomoto.pl Select all the filters (make, model etc.) and see how many pages this generates. If less than 10, copy the URL and paste in the form. One notice: emails seem to not work with Outlook.

The form is available here.

Otodom.pl and gratka.pl are being worked on right now.

This is where the technical part starts.

The script that I created previously was based on RPI + Telegram. This is not a perfect setup, if you want to create a solution available for everyone. I decided to change Telegram for a good ol’ email, and RPI for Azure. Cloud will be helpful here, as I will not have to open any ports or care about constant internet access. A big disadvantage is the fact that I will actually have to pay out of my pocket – hence the limitation.

The whole solution is based on 3 Azure services:

  1. Blob storage – functions as a database. I know that this is not perfect, but it’s super cheap and I have some Python scripts readily available.
  2. Logic App – three apps that manage registration process and downloading offers.
  3. Function – service that lets me run Python without any service (serverless thingy). This way I do not have to set up a new VM.

Using those services, I created four separate (yet cooperating) processes:

  1. Email registration
  2. Email confirmation
  3. Sending out new offers
  4. Subscription removal

Below you can find details of each process and also pieces of code.

1. Email registration

Diag1ENG

Logic app view:

image

The registation process is rather easy to follow. A user registers through a form, which sends a GET request to the logic app. The requests passes user email and the URL from otomoto.pl. The URL is check using a function called GetPages (code below), to check for the number of pages. If it returns more than 10 pages, the users gets a proper response. If it returns less, files are created on blob storage, emails gets an ID, an email is sent with confirmation link and a proper response is shown. Blob storage has a policy, which will delete the files after 2 days (offer URL and email). If the user clicks on the confirmation link after 2 days, it will not work.

OtomotoScrapper class, which contains all the methods:

GetPages:

 

2. Email confirmation:

Diag2PL

Logic app view:

image

When a users click the confirmation link, a check happens to validate email’s id. This (hopefully) will make it impossible to confirm an email address without an actual access to it. Afterwards the process calculates SHA256 hash of the email (using Hash function), this is done so that I have only one place to delete from. The files used for the confirmation are then deleted. A welcome email with subscription removal link is sent. Later a response is shown to confirm the process. The last step is downloading all the existing offers for the moment of confirmation (ScrapHttp).

Hash:

ScrapHttp:

 

3. Sending out new offers

Diag3PL

Logic app view:

image

A few times a day this app is triggered. For each email hash from a selected directory (directories in blob storage are just part of the name) the offers are downloaded. If there are no new offers, nothing happens. If there are some new offers, for the selected hash an email is being found (this information is inside blob storage) and an emails is sent.

4. Subscription removal

Diag4PL

Logic app view:

image

This process starts with a check if the email even exists. If not, a proper response is shown. If the email indeed exists, another check happens to confirm its ID. This will prevent deleting random emails. After this is confirmed, the hash is calculated, and all the files (hash-email pair, email id) are deleted. Downloaded offers are then copied to the archive. Afterwards a response with confirmation is shown.

And that is it! My budget is 5 USD per month, so use it! I monitor closely all the emails, as I know that you can probably bypass the system. If someone pushes it to the limits, I will ban! If you need more frequent notifications, let me know!

I start with a newsletter. If you want to be notified of such great pieces of work – subscribe below.

Leave a Reply

Your email address will not be published. Required fields are marked *