Microsoft Flow – Tweet today’s events from an RSS feed

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:

formatDateTime(item()[‘publishDate’],’yyyy-MM-dd’)

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!

getFutureTime(4,’Hour’,’yyyy-MM-dd’)

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.

2 thoughts on “Microsoft Flow – Tweet today’s events from an RSS feed”

  1. The date handling is interesting…

    If the flow is running at 8am local time, what is local time? Does the flow have a timezone setting that doesn’t get used by the formatting functions?

    Odd that there is a utcNow() but no Now(), especially since the flow has a timezone.

    Why add 4 hours? If you are converting from UTC to AEST then +10 would be my choice, or use convertFromUtc and utcNow for consistency across operations.

    How does it deal with daylight saving? Will it run at 8am all year? Will the hardcoded ‘AUS Eastern Standard Time’ know to change to ‘AUS Eastern Daylight Time’?

    The times in the RSS have a time offset specified, so while assuming UTC is working now, you should parse the offset in case it changes.

    What even is a timestamp in this context? The function reference uses ISO8601, but looks like they are ok with handling RFC822 dates…

  2. The run time is timezone specific. Didn’t show that box. The An action can reference the time it was triggered but it is GMT.
    As the timezone are shown as UTC + and we are choosing the +10 time then I assume the Flow would shift by an hour in daylight savings. Not sure it has an automated way to handle DST.

    Yes I could add 10 hours but it would achieve the same result as I just need to match on date so 4 hours gets me there.

    Interesting note about the RSS time offset. I hadn’t noticed that. All the posts in the RSS feed are showing +0000 as the offset which is UTC 0 / GMT so that wouldn’t help me in this case.

    All the my research about the functions seems to indicate they will read other standards but the default is ISO8601 for output unless you specify.

    I’ve found they have a Convert Time Zone action where you can pick the source timezone and destination timezone. I could technically use that in place of the get future time expression but I’d still be converting the feed time format so I could match just against date.

Leave a Reply