Posting IMDB ratings to Twitter, my first multi-step Zap

I am sure the majority of us reading this article have one way or another automated tasks as part of our day jobs, with services such as Zapier and IFTTT we can easily take this approach for tasks in our personal lives to build integrations between applications we use every day.

In this example, I will be using a ‘Zap’ to automate the task of publishing a tweet containing ratings from my IMBD account for a film or TV series I have recently viewed. On a separate note, I am still quite not sure why this is not integrated as a sharing option for account settings!

What is a Zap? Well lets take the official explanation:

A Zap is a blueprint for a task you want to do over and over. In words, a Zap looks like this:

“When I get a new thing in A, do this other thing in B.”

So in my example, when I post a review to IMDB (A) a message to Twitter should be posted containing my rating(B).

Firstly, I created the trigger which would use the RSS app by Zapier to discover new item feed items from the publicly available URL of the RSS feed of my ratings from IMDB. To retrieve the URL, login to your IMDB account, select ‘Your Activity > Your Ratings’ and select the RSS icon in the right corner.

Also, in order to post you will require the list to be public, to which you will need to select ‘Change list settings’ and select ‘Make this list a public list visible to all public IMDB users’.

Ratings_Screenshot

In my example the URL ‘http://rss.imdb.com/user/ur43561079/ratings’ will be used for the feed. In order to determine what triggers a new feed item, we will select ‘Different Guid/URL’ which is the default option.

Now that we have our trigger for the multi-step task, our final goal is to post a tweet containing content from items retrieving in the feed. In this step I have created an action using the Twitter app to create a Tweet (limited to 10 per hour) and account. Now we are provided with a template which will contain the content of the message you require to post from Twitter. Here you can select items returned from the feed trigger to generate the message by selecting the item returned by selecting a field.

So, lets have a look at the information returned from a new feed item:

      <item>
            <pubDate>Sat, 13 Feb 2016 00:00:00 GMT</pubDate>
            <title>The Man in the High Castle (2015 TV Series)</title>
            <link>http://www.imdb.com/title/tt1740299/</link>
            <guid>http://www.imdb.com/title/tt1740299/</guid>
            <description>
                mail-deangrant-689-891137 rated this 7.
            </description>
            <pubDate>Sat Feb 13 00:00:00 2016</pubDate>
        </item>

In my example, I want to post a message similar to ‘Rated {title} a {rating}. #imdb {link}’. From reading the above we can see that we cannot retrieve a field item only containing the rating score, but only a description item containing the text ‘{username} rated this {rating}’. So lets go back a step, from here I want to select the text pattern containing the rating score. We can achieve this by creating a step prior to posting the message to use the Code app to run python in response to information received from the trigger. In this example we want to provide the description field as the input item (input[‘description’]) and split the string into substrings where the text pattern ‘rated this ‘ is used to split the string and return the item in the array containing the rating score.

string = input['description']
rating = string.split('rated this ',1)[1]

return {
   'rating': rating
}

Now back to posting the message to Twitter we can select the following field items to generate the message as per my requirements. Field items prefixed with Step 1 are items returned from the RSS app and Step 2 being data returned from the Code app.

Zapier_Screenshot_IMDBtoTwitter_Step3

When the zap is run, and a new feed item is discovered the message should be posted to twitter based on the template created above and should read similar to the item below:

Twitter_Screenshot_Zap_Post

Finally, if we look at the task history we can see how the zap was triggered and data in and data out received/returned during invocation of each step.

Step 1 – Found 1 new in Item in Feed in RSS.

Data In

url:
http://rss.imdb.com/user/ur43561079/ratings
trigger_style:
smart

Data Out 

description:
mail-deangrant-689-891137 rated this 7.
pubDate:
Sat, 13 Feb 2016 00:00:00 GMT,Sat Feb 13 00:00:00 2016
title:
The Man in the High Castle (2015 TV Series)
raw__guid:
http://www.imdb.com/title/tt1740299/
raw__link:
http://www.imdb.com/title/tt1740299/
raw__pubDate:
Sat, 13 Feb 2016 00:00:00 GMT,Sat Feb 13 00:00:00 2016
raw__description:
mail-deangrant-689-891137 rated this 7.
raw__title:
The Man in the High Castle (2015 TV Series)
link:
http://www.imdb.com/title/tt1740299/
guid:
http://www.imdb.com/title/tt1740299/
id:
http://www.imdb.com/title/tt1740299/
Fields with no value:
content

Step 2 – Sent 1 new Run Python to Code.

Data In 

input:
description:
mail-deangrant-689-891137 rated this 7.
code:
string = input['description']
rating = string.split('rated this ',1)[1]

return {
   'rating': rating
}

Data Out 

runtime_meta:
duration_ms:
1
memory_used_mb:
20
logs:
rating:
7.
id:
HmFhdaYZDDFsYw0iVXiGETIf1STwsiKj

Step 3 – Sent 1 new Tweet to Twitter

Data In 

message:
Rated The Man in the High Castle (2015 TV Series) a 7. #imdb http://www.imdb.com/title/tt1740299/

Data Out 
N/A
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s