#!/usr/bin/env bash # Source the common utils and the environment variable loader source load_common_and_env.sh # (Attempt to) take variable we need BENUTZERID=${MENSA_USER} PASSWORT=${MENSA_PASS} FF3PAT=${FF3_PAT} FF3URL=${FF3_URL} # Fixed variables AUTHORIZATION="S0FTVkM6ekt2NXlFMUxaVW12VzI5SQ==" USER_AGENT="Mozilla/5.0 (Windows NT 10.0; rv:120.0) Gecko/20100101 Firefox/120.0" # Function to format date to DD.MM.YYYY format_date() { date -d "$1" '+%d.%m.%Y' } # Function to get Unix timestamp get_unix_timestamp() { echo $(date +%s) } # Function to url-encode strings url_encode() { local encoded="" local length="${#1}" for (( i=0; i /dev/null; then # Special handling for "Karte aufwerten" date=$(echo "$transaction" | jq -r '.date') formatted_date=$(format_date_for_firefly "$date") totalAmount=$(echo "$transaction" | jq -r '(-1 * .totalAmount)') # echo "Recharge:" firefly_data=$(jq -n \ --arg date "$formatted_date" \ --arg amount "$totalAmount" \ '{ error_if_duplicate_hash: true, apply_rules: false, transactions: [ { type: "transfer", date: $date, amount: $amount, description: " Guthaben Mensa", category_id: 5, source_id: 31, destination_id: 45, } ] }') else # Extract and format transaction data date=$(echo "$transaction" | jq -r '.date') formatted_date=$(format_date_for_firefly "$date") totalAmount=$(echo "$transaction" | jq -r '.totalAmount') notes=$(echo "$transaction" | jq -c '[.items[] | "\(.menge): \(.name) (\(.epreis) €)"]') mensa=$(echo "$transaction" | jq -r '.mensa') # echo "$notes, $totalAmount" # Prepare the data for the Firefly III API firefly_data=$(jq -n \ --arg date "$formatted_date" \ --arg amount "$totalAmount" \ --argjson notes "$notes" \ --arg tag "$mensa" \ '{ error_if_duplicate_hash: true, apply_rules: false, transactions: [ { type: "withdrawal", date: $date, amount: $amount, description: ("Essen " + $tag), budget_id: "2", category_id: "1", source_id: "45", destination_id: "191", tags: [$tag], notes: (if $notes | length == 0 then null else $notes | join(" \n") end) } ] }') fi # Create the transaction in Firefly III # echo "$firefly_data" create_firefly_transaction "$firefly_data" done