Loading...
 
Minimalistic Text Wiki » Make an currency exchange rate widget with Minimalistic Text, Tasker and a hosted PHP script
Print

Make an currency exchange rate widget with Minimalistic Text, Tasker and a hosted PHP script

This tutorial will show how to make a widget showing the exchange rate between two currencies. This can be potentially handy if you're traveling to a foreign country or living abroad.

Please note that this is a somewhat advanced tutorial and probably not the best place to learn how to use Minimalistic Text and Tasker.

For this tutorial you will need:

  • Minimalistic Text
  • Tasker
  • A place to host a PHP script (or some other way of obtaining the exchange rate)


We will start at the bottom of this list and work our way up to what eventually will be the widget.

Obtaining the exchange rate (with PHP)

The script below will use Google's currency converter to find the exchange rate:

<?php
/*
 * Simple currency converter using Google search.
 * Inspired by Tudor Barbu's similar script at http://blog.motane.lu/2008/12/19/currency-conversion-in-php/
 *
 * Made by: Paul Levold, paul.levold@gmail.com
 * Released in the public domain
 */

$amount = $_REQUEST['amount'];
$currency = $_REQUEST['curr'];
$exchangeIn = $_REQUEST['incurr'];
$prec = $_REQUEST['prec'];

$googleQuery = $amount . ' ' . $currency . ' in ' . $exchangeIn;
$googleQuery = urlEncode( $googleQuery );
$askGoogle = file_get_contents( 'http://www.google.com/search?q=' . $googleQuery );
$matches = array();
preg_match('/= ([0-9]*\.[0-9]*)/', $askGoogle, $matches);
$rate = $matches[1];

echo round($rate,$prec);
?>


Place this script on your server, let's say www.whatever.com/currency.php. The script takes four parameters. They are given to the script in the URL using a get method (example below):

  • amount: The amount in original currency
  • curr: The acronym for the original currency
  • incurr: The acronym for the currency which the amount should be converted to
  • prec: The desired precision (number of digits after the comma)


It will return a single number (no html), which is the amount in the foreign currency. For example, www.whatever.com/currency.php?amount=1&curr=gbp&incurr=usd&prec=2 will (at the moment) return 1.63. This is the same as typing "1 usd in gbp" into Google and rounding it off after two digits.

There is no reason that any other approaches than a PHP script will work. If you got another solution you'd like to use, just use that.

Setting up Tasker

In Tasker, press new, choose Time and set the time to the time when you would like the the exchange rate to be updated. check the repeat box if you wish to update the exchange rate several times during the day. You should ensure that your phone has data connection if the updates are to be successful. You can also make other profiles that trigger the update if you wish. For example, updates could be initiated every time a new WiFi connection is made on the phone.

Click Ok to create the profile and click New Task to create a new task. Click the plus icon, choose Net and then HTTP Get to add an action which will call the PHP script and get the latest exchange rate.

In the HTTP Get dialog, type in the following settings:
- Server:Port:
www.whatever.com/currency.php (obviously that should be replaced by your actual URL
- Attributes:
''amount=<1 or 100, depending on the currency>
curr=<your original currency>
incurr=<the currency you wish to convert to>
prec=2'' (Note that each attribute should be placed on a separate line)
- Output File:
exrate.txt (a note on this later)

This will tell Tasker to query the URL and save the data in the text file exrate.txt. In principle Tasker will save the data in the variable %HTTPD. For some reason, Tasker did not do this to me so I had to store it in a text file instead. If this variable works for you, skip the next two paragraphs.

Add a new action by clicking the plus sign, Variable and Variable Add. Name the variable %LINE and set the value to 1.

Add a new action by clicking the plus sign, File and Read Line. Set the file name to exrate.txt, line to %LINE and "to var" to %EXRATE. This will read the exchange rate into the variable %EXRATE if the %HTTPD variable mentioned above did not work for you either.

Add the final action by clicking the plus sign, Plugin and Minimal Text variable settings. Click Edit and type %EXRATE into both text fields. Note: If Tasker did store the data in %HTTPD for you, change the "variable content" field to %HTTPD.

To download the first exchange rate manually, press Test.

Set up the Minimalistic Text widget

Go to your home screen and add a new Minimalistic Text widget. Click Predefined Layout and Custom.... Then click Custom layout below.

Remove the fields already there by long pressing on them and moving them to the bin.

Press the plus button on the right hand side, choose Misc and drag the Static Text box out to the widget. Click the box and type <your amount> <your original currency> = into the text box.

Press the plus button again and drag a Locale variable box and place it after the static text box. Click it and in variable name, type %EXRATE.

Add another static text to the end with the text with the text <the currency you wish to convert to>.

And you're done! Now, tweak the settings for your own desire.

TODO: Add screenshots.


Minimalistic Text links

Market: Minimalistic Text
Market: Minimalistic Text (donate)
XDA Thread
Devmil on Twitter

Minimalistic Text on Facebook

Image

Donation link

Donate @ Paypal

Tresorit

If you are looking for a secure Cloud Storage and don't mind spending some cash for your privacy then Tresorit is the right place to go. It uses a zero knowledge approach and is based in Europe
Referral link
Image

Old Minimalistic Text version

Minimalistic Text v2.6.3 (Android 1.6)


Show php error messages