1 files changed, 31 insertions(+), 8 deletions(-)

M Scripts/curconv
M Scripts/curconv +31 -8
@@ 1,16 1,39 @@ 
-#!/bin/sh
-# from Ambrevar https://bbs.archlinux.org/viewtopic.php?pid=1568235#p1568235
+#!/bin/bash
+# adaptedfrom Ambrevar https://bbs.archlinux.org/viewtopic.php?pid=1568235#p1568235
+
+# File to log the arguments
+curhist="$HOME/Sync/Centurion/curhistfile"
 
-if [ $# -ne 3 ] || [ "$1" = "-h" ]; then
-	cat <<EOF
+# Function to log and print messages
+log_message() {
+local timestamp=$(date +"%d-%m-%y")
+    # Log with date to the file
+    printf "[%s] %s\n" "$timestamp" "$1" >> "$curhist"
+    # Print message to stdout
+    printf "%s\n" "$1"
+}
+
+if (( $# != 3 )) || (( "$1" == "-h" )); then
+    cat <<EOF
 Usage: ${0##*/} VALUE IN-CURRENCY OUT-CURRENCY
 
 Convert VALUE from IN-CURRENCY to OUT-CURRENCY.
 CURRENCY is a 3-letters code like EUR, SEK, USD, etc.
 
 EOF
-	exit
+    exit
 fi
-curl -sA "Mozilla/5.0" "https://www.calculatorsoup.com/calculators/financial/currency-converter.php?input_value="$1"&input="$2"&output="$3"&action=solve" \
-    | awk -F'<|>' '/div id="answer"/ {print $11}'                                                                                                                                     
-     
+
+# Log the arguments
+log_message "$1 $2 $3"
+
+# Fetch conversion and log the result
+RESULT=$(curl -sA "Mozilla/5.0" "https://www.calculatorsoup.com/calculators/financial/currency-converter.php?input_value=$1&input=$2&output=$3&action=solve" \
+    | awk -F'<|>' '/div id="answer"/ {print $11}')
+
+if [[ -n "$RESULT" ]]; then
+    log_message "$RESULT"
+    printf "\n" >> "$curhist"
+else
+    log_message "Failed to fetch conversion result."
+fi