Here's how to retrieve and display the latest exchange rate for two currencies with the Workflow App (though one could just use Numbers on iOS or macOS too).

I will be using Google's Currency Conversion. To determine the currency codes supported, you'll have to visit the page and use View Page Source to look at the <option value= elements. Yahoo also has an equivalent tool without the UI, that outputs CSV instead.

A Uniform Resource Locator (URL) is more than just the "web address" of a web site or web page. It can also contain input parameters for the page that may change the contents of what is returned. This part of the URL is called the Query String, and starts with the first ? e.g. http://www.test.com/test.html?key1=value1&key2=value2.

Workflow Actions

First, create a List and fill it with the currency codes you desire converted. Then prompt to Choose From List for the "from" currency.

Workflow From Currency Choose From List

Next, retrieve the list again with Get Variable. By now I'm sure you know that the Variable List is a Magic Variable from the first Action. And Choose From List again for the "to" currency. Since I may want this to run as a Notification Center Widget, I do not select Select Multiple and besides, that would make the code more complex.

Workflow To Currency Choose From List

Now, to build the URL query string to Google's page, add Text with https://www.google.com/finance/converter?a=1&from=[[first chosen item]]&to=[[second chosen item]], selecting the first and second chosen items in that order. I have fixed the amount to 1, to avoid additional user input. Get Contents of URL will make the HTTP request and Get Text From Input will convert the response into text, stripping all HTML (HTML is the code that specifies the formatting, placement and other attributes of the text).

Workflow Get Contents of URL and Get Text From Input

It's possible to retain the HTML by replacing Get Text From Input with Make HTML From Rich Text, but it's easier to convert to text.

Use Match Text to search for text matching the pattern in the regular expression 1.* = [\d.]* .*. Enter this exactly, including the three spaces! Finally, Alert will display the matching result, e.g. 1 USD = 0.9183 EUR

Workflow Match Text and Show Alert

All done!

Adapted from Currency Converter (Google Finance) on Workflow.is

Related Posts

Newer Post Older Post