I started a little community project a few years ago called
Melbourne Theatre Calendar with the aim of listing all of the theatre shows in Melbourne in a single place. It came out of frustration that when I wanted to go see a show I couldn’t easily see what was playing ‘today’ or ‘tomorrow’.
Now that the site has a lot of content, I want to expand how I can share the information starting with Twitter. The site is built upon WordPress with The Events Calendar plugin and that plugin provides an RSS feed of the next 10 events.
After playing around with some online services that can Tweet from an RSS feed, I decided I could get a better outcome for free by using Microsoft Flow.
My goal was pretty simple, at 8am every day (local time), tweet all today’s events as individual tweets from the RSS feed. No events today, no tweet.
One small challenge is that the RSS feed contains the next 10 events regardless of event date so this needed to be accommodated.
A high level view of the resulting flow looks like Recurrence, List all RSS feed items and Apply to each.
In more detail, it it’s built as follows:
Recurrence, this is the easy part. Interval of 1 Day, running at 8am.
List all RSS feed items, also pretty straight forward. We can’t use the since option as the RSS feed could also be showing future events so we’ll do the filtering in the next step
The Apply to each action step is where things get more interesting and for me, actually started with the Condition action.
The finished result is pictured below but I’ll walk you through how it was created.
Choosing a new action below the RSS feed, I selected the Condition Control action.
You are then presented the condition statement area and If yes and If no sides of the condition.
The condition statement is just a true or false, yes or no test.
If something IS something where the IS could be equal to, greater than, contains, does not contain and so forth.
For me I wanted the statement along the lines of [date of RSS feed item] [is equal to] [todays date].
Starting on the left side of the statement, I chose the dynamic field from the RSS feed called Feed published on.
When you do this, Flow automatically wraps an Apply to each action around the condition as it reccognises that an RSS feed has multiple items. It puts the dynamic field Body in in the select and output from the previous steps box for you too.
The test is is equal to.
The right hand side of the statement was more of a challenge to figure out and I turned to the Microsoft Flow Community for some suggestions after hitting a few brick walls.
As my test is related to the date only, I needed to first convert the Feed published on value to a date only format.
This is achieved using the formatDateTime function with the yyyy-MM-dd format string.
The end result on the left side of the statement therfore became:
With the feed item date now on the left, I needed to get today’s date to compare it to.
It was suggested I use the utcNow function but I found this wouldn’t work due to timezone differences. As I was running this flow at 8am UTC+10 this would return a value of 22:00 UTC the day before and never match the UTC date values of events that were afternoon and evening based.
Enter the getFutureTime function. By using this to add 4 hours to the returned value, I could ensure that converted date would always be the same date as the event. It has it’s own date format string too!
Now onto the the actions. I first built this Flow with the actions outputting to email. I reccomend this whilst you’re nutting out problems with your Flow as you can use obvious text to indicate whether the email was the result of the statement being true or false.
The If no was always going to be blank as if the feed item wasn’t for an event today, I didn’t want it tweeted.
The If yes was the Post a tweet action. As the RSS events were is UTC, I needed to convert them to the correct timezone with the convertFromUtc function. With this you set the timezone and the display format.
convertFromUtc(items(‘Apply_to_each’)?[‘publishDate’],’AUS Eastern Standard Time’,’f’)
The finished Flow looks as below.