Entries filed under Python

Calculate exchange rates with Alfred 2 workflow

Alfred 2 is awesome productivity application for Mac OS X. It allows you to quickly search files, navigate web, run applications and many more. One of the great features of Alfred are workflows – custom actions, that can be triggered (and programmed) by the user.

As a solution to my frequent need of calculating the exchange rates between currencies, I made an Alfred 2 workflow that allows to do exactly that, using Google-like syntax, for example:

rate 123 USD in EUR

will yield result:

90.44 EUR

Here’s a screenshot:

alfred-currencies screenshot

alfred-currencies screenshot

You can download the workflow here. Installation instructions are on the project’s Github page, as well as the code and issue tracker.

Monitoring your services with Papertrail and Heroku

Recently I have noticed some problems with my Internet connection, sometimes it was completely unavailable. I concluded that I need some precise information about the outages, so I can talk to my ISP. As at the same time I learned about the Paper Trail service, I decided to use it in my setup. Other thing, that I wanted to learn was Heroku, so I gave it a try. Both services have some free tier, which is perfectly sufficient for my needs.

The architecture of my solution is as follows: I have local server running on Raspberry Pi (as mentioned in one of the previous posts about the online radio streaming). On this server, I have a Python script, running as a cron job every 10 minutes. This script sends simple log message to my Papertrail account. Then, I have another Python script, that runs every 10 minutes as a scheduled job on Heroku. This script checks, if there are recent “heartbeat” logs on Papertrail and if not – sends an e-mail message. You can download the source code of both scripts from the github repository.


How to force Gmail to check your POP3 account as often as possible

One, of the killer features of Gmail (in my opinion) is ability to collect e-mails from external POP3 accounts and send messages via external SMTP servers. This way, one can use Gmail as slick, web based e-mail client to virtually any account in any domain, with the benefit of IMAP access, labels, autoresponders, spam filtering, etc.

Unfortunately, Gmail uses “intelligent” algorithm to figure out, how often it should collect e-mail messages from your POP3 server. It is based on the amount of mail you get – if you receive merely few messages per day, Gmail will check the server twice every hour. In extreme situation it means 29-minute delay in delivering the message that you are waiting for – not very convenient lag, hard to accept in the 21st century. If you get your e-mails often, Gmail is going to check your account every five minutes or so.

So, how to get your account checked every few minutes (= almost no delay in delivery of your important messages)? Lure Gmail into thinking, that you get maaany important emails every few minutes. You can accomplish it by simple Python script, that you should run on your server (i.e. Raspberry Pi with Raspbian, that you can run in your home). (Click “Continue…”)