summaryrefslogtreecommitdiff
path: root/xe
blob: 2375df67beb8a8e5dd1bf466e8d30ea2d8db931e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash

set -e

if [ $# = 0 ] ; then
    exit 0
fi

if ! (hash phantomjs >/dev/null 2>&1) ; then
    exit 1
fi

from=${1:0:3}
to=${1:3:3}

get_value() {
    script=$(tempfile)
    url="https://www.xe.com/currencyconverter/convert/?Amount=1&From=$from&To=$to"
    cat <<EOF >$script
    var page = require('webpage').create();
page.open('$url', function(status) {
    if (status !== 'success') {
        console.log('Unable to access network');
    } else {
        var ua = page.evaluate(function() {
            return document.querySelector('.converterresult-toAmount').textContent;
        });
        console.log(ua);
    }
    phantom.exit();
});
EOF
    timeout 15s phantomjs $script | head -n 1
    rm $script
}

get_value $from $to