commit f1a395fc5fecfff2de821544820ac543cf0759b4
parent f8ae85b1aeabf73aa55a1e0691f0f474fd5d9979
Author: Alex Balgavy <alex@balgavy.eu>
Date: Mon, 25 Apr 2022 10:42:59 +0200
xe: a script to get exchange rates from xe.com
Diffstat:
1 file changed, 18 insertions(+), 0 deletions(-)
diff --git a/scripts/xe b/scripts/xe
@@ -0,0 +1,18 @@
+#!/bin/sh
+# A CLI utility for exchange rates via https://www.xe.com
+
+die() { printf '%s\n' "$1" >&2 && exit 1; }
+
+[ $# -eq 3 ] || die 'Usage: xe AMOUNT FROM_CURRENCY TO_CURRENCY'
+amount="$1"
+from="$(printf '%s' "$2" | tr '[[:lower:]]' '[[:upper:]]')"
+to="$(printf '%s' "$3" | tr '[[:lower:]]' '[[:upper:]]')"
+
+curl -sL "https://www.xe.com/currencyconverter/convert/?Amount=$amount&From=$from&To=$to" \
+ -H 'authority: www.xe.com' \
+ -H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \
+ -H 'accept-language: en-US,en;q=0.9,uk-UA;q=0.8,uk;q=0.7,ru-RU;q=0.6,ru;q=0.5' \
+ -H 'cache-control: no-cache' \
+ -H 'pragma: no-cache' \
+ -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36' \
+ | pup 'p[class*=result__BigRate] text{}' | tr -d '\n'