Stampante termica con raspberry Pi

March 27, 2022 - Reading time: 2 minutes

Piccolo esperimento realizzato con script in bash, di seguito:

Di seguito lo script da mandare in output verso la stampante (script.sh > /dev/usb/lp0)

#!/usr/bin/env bash

API='https://markets.businessinsider.com/ajax/'

ExchangeRate_GetConversionForCurrenciesNumbers() {

  isoCodeForeign=$1

  isoCodeLocal=$2

  amount=$3

  date=$4

  cacheFile="/tmp/$date-$amount-$isoCodeForeign-$isoCodeLocal.json"

  if ! [ -e "$cacheFile" ]; then

    post_vars=(

      isoCodeForeign="$isoCodeForeign"

      isoCodeLocal="$isoCodeLocal"

      amount="$amount"

      date="$date"

    )

    method='ExchangeRate_GetConversionForCurrenciesNumbers'

    IFS='&' url="$API$method?${post_vars[*]}"

    curl -s -X POST "$url" > "$cacheFile"

  fi

  jq -r '.ConvertedAmountFourDigits' "$cacheFile"

}

getRateEURO_USToday() {

  ExchangeRate_GetConversionForCurrenciesNumbers EUR BRL 1 "$(date '+%Y-%m-%d')"

}

LC_NUMERIC=C printf 'The exchange rate for EUR to BRL today is: %.4f\n' \

"$(getRateEURO_USToday)"

printf "\n"

date

printf "\n"

printf "\n"

rm /tmp/20*

About

Questo blog è un sito personale, con materiale scritto da me e i miei contatti di seguito:

mail: a@irxer.com