InformIT ebook deal of the day → pushbullet

In case you are like me and like reading, has a rather large library of ebooks, some of which they offer in daily deals.

These “daily deals” are pretty good thing because you can end up getting a classic like Fowler’s “Refactoring” or GoF’s “Design Patterns” with a 50% discount.

But, the publisher wants you to visit their page every day. They don’t offer a newsletter for example (and their Twitter is overloaded with corporate information so it’s hard to see only the tweets related to the DoDs).

So, how can we automate getting the information? I’ve made a one-liner bash command that sends Pushbullet notifications via cron. Let’s go step by step…

If you open the HTML source code of the page you can see that the link to the book is the first link that starts with:

<a href="/store

So, the simplest way is to download the page and just extract the first link that matches this expectation. Of course, it will not work forever, but you can always come back and report it here, I might need to update this pattern…

Simplest way I found to extract the script is:

curl 2>/dev/null | \
  sed -n 's/.*href="".*/http:\/\/\1/p' | \
  head -1

The upper script will:

  1. download the page, hiding the progress bar

  2. it will replace all lines that have store links with the link content only

  3. show only the first match

How do we now get the link? You can choose to send an email, but that’s so 1990's! Let’s find a more modern approach for this!

I have a Pushbullet app on my phone and, interestingly enough, guys keep it quite cheap (until you start sending a lot of notifications), so let’s use that one!

| xargs -I {} curl \
  --header "Access-Token: $PUSHBULLET_TOKEN" \
  --header 'Content-Type: application/json' \
  --data-binary '{"body":"Deal of the day is: {}","title":"InformIT deal of the day","type":"note"}' \
  --request POST

The command is almost a literal copy&paste from the official API documentation — you need though a Bash environment property PUSHBULLET_TOKEN which carries the private access token provided on the page and that’s it.

Putting it in a script

Everything done until now is just a preparation for the last step: we need a way to check this daily instead of us executing the command (otherwise it would’ve just been easier to open the browser, right?).

Let’s save the command we’ve built in previous 2 steps into a file “/home/” (with executable bit turned on of course).

#!/usr/bin/env bash

# command we've built above>

I don’t really do it like this though in my machines: I tend to extract all of the important environment properties into a separate file I keep in Git, but of course in this article I’m keeping it simple.

Using cron to get daily notification

I will use a standard crontab to do this. Depending on your setup you can use different ways: supervisord or systemD just to name a few. I still think crontab is the simplest/most generic way.

crontab -e

And, finally, add this line in the editor presented to you and it’s done!

5 10 * * * /home/ 2>&1 > /tmp/pushbullet.log

Since I live in Brussels, I chose 10:05 AM to generate notification, around 1 hour after it is published. You, of course, need to adapt the time to your time zone.

Of course, while experimenting, you might want to replace “5 10” with “*/1 *” so you can send notification every minute, until you’re sure everything works.