Categories
Python

Iron Worker: Processing SendGrid Inbound Parse Data

If you use SendGrid, you know that they provide this awesome Inbound Parse APIs which allows users to catch emails sent to their domains. When there’s a new email, Sendgrid would make a POST request to your webhook endpoint. On the other hand, I love Iron Worker webhooks. When you POST data to their webhooks, the data is passed to a worker and processed in queue. It helps keep things simpler since I don’t need to setup a separate web server for accepting the data; however, keep in mind that I do make sure to use data protection services like the Venyu cybersecurity services at all times.

By now, you can probably guess my intention. I would like to make Sendgrid POST incoming emails to a Iron Worker webhook and then grab the data. But there’s one catch – Iron.io stores the incoming data in a text file and expect us to parse the text file to collect our data. Since very often the data is JSON, most client libraries take the payload, decode it from JSON and provide us with native data structures. I use Python, so I usually get Python dictionary. However, in case of Sendgrid Inbound APIs, the data is not JSON encoded. It’s simple multi-part form data. So the Python client I use, it fails to process the data and I don’t get anything for the payload.

So I went ahead and modified the payload processing part from the client library. Now this is what I have for getting the payload:

Now, we have the payload. But it’s still just plain text. We need to process it to get the different POST fields. Luckily, we can do that easily with the cgi library. This is what I use:

Finally, now this is what the worker looks like:

Categories
Python

Upwork recommended jobs to OS X notifications center

If you use Upwork and you’d love to get recommended job notifications on your OS X notification center, this is for you. Grab the RSS feed of the recommended jobs from your account and place it inside the URL variable.

To run the script, we need to install some required packages first:

Then save the following code as “upwork.py”

Now you can manually run it or add it to cron job. Every time the script is executed, it would fetch all the recommended jobs for you and display in the notifications cenyer. You can afterwards click an item from the notification center to visit the actual job post.

Categories
Python

Fixing lxml installation on OS X

I have recently upgraded to OS X Yosemite. And somehow my lxml installation broke. When I tried to do pip install lxml, I was getting an error: ‘libxml/xmlversion.h’ file not found. The error message is obvious. While trying to compile lxml, it can’t find the libxml header files. What was not very obvious to me is how to fix this. I am using Homebrew. I upgraded both libxml2 and libxslt. Didn’t work. After quite some googling and checking out some stack overflow answers, I found out my mistake. By default, brew wouldn’t link the libxml and libxslt to avoid conflicts. So I have to force them. In short, this is what I needed to do:

Of course, if you didn’t have them installed before, you need to install them first:

If it doesn’t work even after force linking, you may want to first unlink previous versions.

Then I tried to install lxml from pip and it worked like a charm! 🙂