Recently, I was looking for a new apartment in New York. It’s obvious that the first place where you need to start looking for something is craigslist. I didn’t find any way to receive emails when somebody posts a new ad which has specific keywords and matches my filters. I decided to write a small script which could solve this problem. I’ve had some experience with groovy and wanted to refresh my memory.
##Let’s get it started
What we need? Not so long ago I began to choose gradle for each project. This’s not an exception too.
This build script is pretty simple. I added application plugin just for testing, you don’t really need it.
As for dependencies - we need:
groovy is needed for project compilation
jsoup is good lib for html DOM manipulations in JQuery style
javax.mail is simplest way to email sending
Let’s write some groovy code.
This code is pretty simple. We have file old for accumulating ads which have been sent. After that we parse current results and check if we have it in list of sent ads. The implementation of simpleMail was grabbed from here without any changes - didn’t want to write it by myself.
That’s it! Now we can start using it.
Running the app
First of all we have to build our app. It’s easy enough. We need to execute only one gradle task.
It produces craigslist-1.0.jar. Now we need to copy this file to folder where the app will be executed. Also you need to create app.properties with following content:
For statring the app I use small bashscript and start it by cron every 5 minutes.
Developement with groovy is pretty fast and effective. I spended ~1 hour for full development and configuration. I didn’t get any troubles during development and building jar file and I got what I wanted.