Compare commits
No commits in common. "master" and "v2025.04" have entirely different histories.
37
README.md
37
README.md
@ -2,18 +2,16 @@
|
||||
|
||||
Wallos Fetcher is a command-line utility designed to retrieve and export subscription data from a self-hosted [Wallos](https://github.com/WallosApp/Wallos) instance—an open-source personal subscription tracker.
|
||||
|
||||
This script helps you keep track of all your recurring expenses and share that information in human-readable or machine-readable formats. It's especially useful for budgeting, personal finance planning, and digital legacy preparation for family members.
|
||||
This script helps you keep track of all your recurring expenses and share that information in human-readable or machine-readable formats, making it especially useful for budgeting, personal finance planning, and digital legacy preparation for family members.
|
||||
|
||||
---
|
||||
|
||||
## ✨ Features
|
||||
|
||||
- 📄 **Markdown output by default** – clean, readable reports
|
||||
- 📊 **CSV output** – spreadsheet-friendly for Excel, Numbers, etc.
|
||||
- 📄 **Markdown output by default** – easy to read, easy to share
|
||||
- 💾 Export as **Markdown**, **CSV**, or **JSON**
|
||||
- 🔍 Optionally include **full subscription details** (e.g., cycle, auto-renew, currency)
|
||||
- 🗃 Output to a custom file
|
||||
- 🧼 Modular, readable Bash script using secure temp file handling
|
||||
- 🧰 Lightweight, portable, and dependency-minimal (requires `curl` and `jq`)
|
||||
|
||||
---
|
||||
@ -46,8 +44,6 @@ chmod +x wallos-fetch.sh
|
||||
./wallos-fetch.sh [options]
|
||||
```
|
||||
|
||||
> ℹ️ This script requires `curl` and `jq`. Run `./wallos-fetch.sh --help` to see all options.
|
||||
|
||||
### ✅ Example Commands
|
||||
|
||||
| Purpose | Command |
|
||||
@ -94,34 +90,11 @@ Structured export for use in spreadsheets or data processing tools.
|
||||
- Default fields: `id,name,price,next_payment,category_name,payment_method_name`
|
||||
- `--full` option adds: `currency_id,cycle,auto_renew`, etc.
|
||||
|
||||
```csv
|
||||
"id","name","price","next_payment","category_name","payment_method_name"
|
||||
"1","Netflix","17.99","2025-04-21","Entertainment","Credit Card"
|
||||
"2","Spotify","9.99","2025-05-01","Music","PayPal"
|
||||
```
|
||||
|
||||
### 📦 JSON
|
||||
|
||||
Raw response data from the Wallos API—useful for backups, custom reporting, or integrations.
|
||||
|
||||
```json
|
||||
{
|
||||
"subscriptions": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Netflix",
|
||||
"price": 17.99,
|
||||
"currency_id": "USD",
|
||||
"next_payment": "2025-04-21",
|
||||
"category_name": "Entertainment",
|
||||
"payment_method_name": "Credit Card"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
Raw response data from the Wallos API—useful for backups or integrations.
|
||||
|
||||
---
|
||||
|
||||
## 🔐 Authentication
|
||||
|
||||
You can set your API key in one of two ways:
|
||||
@ -152,8 +125,6 @@ API_KEY="your_api_key_here"
|
||||
|
||||
> ⚠️ Be cautious: hardcoding secrets in scripts can pose a security risk if the file is shared or version-controlled.
|
||||
|
||||
---
|
||||
|
||||
## 📜 License
|
||||
|
||||
This project is licensed under the [GNU General Public License v3.0 or later](https://www.gnu.org/licenses/gpl-3.0.html).
|
||||
@ -163,7 +134,7 @@ This project is licensed under the [GNU General Public License v3.0 or later](ht
|
||||
## 🤝 Contributions
|
||||
|
||||
Feedback, bug reports, and pull requests are welcome!
|
||||
Submit issues or improvements via the Gitea repository.
|
||||
Submit issues or improvements via your Gitea repository.
|
||||
|
||||
---
|
||||
|
||||
|
||||
190
wallos-fetch.sh
190
wallos-fetch.sh
@ -1,123 +1,161 @@
|
||||
#!/bin/bash
|
||||
|
||||
VERSION="2025.05"
|
||||
VERSION="2025.04"
|
||||
|
||||
# Configuration
|
||||
HOST="https://your-api-host.com"
|
||||
ENDPOINT="/api/subscriptions/get_subscriptions.php"
|
||||
API_KEY="${API_KEY:-$WALLOS_API_KEY}"
|
||||
|
||||
# Defaults
|
||||
MODE="md"
|
||||
FULL=false
|
||||
OUTPUT=""
|
||||
TMP_FILE=$(mktemp)
|
||||
|
||||
# 🚨 Dependencies check
|
||||
for dep in curl jq; do
|
||||
command -v "$dep" >/dev/null 2>&1 || {
|
||||
echo "❌ Missing required dependency: $dep"
|
||||
exit 1
|
||||
}
|
||||
done
|
||||
OUTPUT="" # Will set default per mode later
|
||||
|
||||
# Show help
|
||||
show_help() {
|
||||
cat << EOF
|
||||
ℹ️ Wallos Fetcher Script - v$VERSION
|
||||
|
||||
Usage: ./wallos-fetch.sh [OPTIONS]
|
||||
|
||||
Fetch and export subscription data from a Wallos instance.
|
||||
|
||||
Options:
|
||||
--json Output raw JSON
|
||||
--md Output Markdown table
|
||||
--csv Output CSV table
|
||||
--full Include more fields
|
||||
--full Include more fields in CSV/Markdown
|
||||
--output <file> Custom output filename
|
||||
--help Show this help message
|
||||
--version Show version
|
||||
--help Show this help message and exit
|
||||
--version Show version and exit
|
||||
|
||||
Default output is Markdown.
|
||||
EOF
|
||||
}
|
||||
|
||||
parse_args() {
|
||||
while [[ "$#" -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--json) MODE="json" ;;
|
||||
--md) MODE="md" ;;
|
||||
--csv) MODE="csv" ;;
|
||||
--full) FULL=true ;;
|
||||
--output) shift; OUTPUT="$1" ;;
|
||||
--help) show_help; exit 0 ;;
|
||||
--version) echo "🧾 wallos-fetch v$VERSION"; exit 0 ;;
|
||||
*) echo "Unknown option: $1"; show_help; exit 1 ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
# Argument parser
|
||||
while [[ "$#" -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--json) MODE="json" ;;
|
||||
--md) MODE="md" ;;
|
||||
--full) FULL=true ;;
|
||||
--output)
|
||||
shift
|
||||
OUTPUT="$1"
|
||||
;;
|
||||
--help) show_help; exit 0 ;;
|
||||
--version) echo "❓ wallos-fetch v$VERSION"; exit 0 ;;
|
||||
*) echo "Unknown option: $1" && show_help && exit 1 ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# Set default output filename
|
||||
[[ -z "$OUTPUT" ]] && OUTPUT="subscriptions.${MODE}"
|
||||
}
|
||||
# Set default filenames if none specified
|
||||
if [[ -z "$OUTPUT" ]]; then
|
||||
case "$MODE" in
|
||||
json) OUTPUT="subscriptions.json" ;;
|
||||
md) OUTPUT="subscriptions.md" ;;
|
||||
csv) OUTPUT="subscriptions.csv" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
fetch_data() {
|
||||
URL="${HOST}${ENDPOINT}?api_key=${API_KEY}"
|
||||
RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" "$URL")
|
||||
STATUS=$(echo "$RESPONSE" | sed -n 's/^HTTP_STATUS://p')
|
||||
BODY=$(echo "$RESPONSE" | sed '/^HTTP_STATUS:/d')
|
||||
# Construct the API URL
|
||||
URL="${HOST}${ENDPOINT}?api_key=${API_KEY}"
|
||||
|
||||
echo "$BODY" > "$TMP_FILE"
|
||||
# Perform the request
|
||||
RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" "$URL")
|
||||
BODY=$(echo "$RESPONSE" | sed -n '1,/^HTTP_STATUS:/p' | sed '$d')
|
||||
STATUS=$(echo "$RESPONSE" | tr -d '\n' | sed -e 's/.*HTTP_STATUS://')
|
||||
|
||||
if [[ "$STATUS" != "200" ]]; then
|
||||
echo "❌ API request failed with status: $STATUS"
|
||||
rm -f "$TMP_FILE"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
echo "HTTP Status: $STATUS"
|
||||
|
||||
output_json() {
|
||||
mv "$TMP_FILE" "$OUTPUT"
|
||||
echo "💾 Saved JSON to $OUTPUT"
|
||||
}
|
||||
if [ "$STATUS" -eq 200 ]; then
|
||||
echo "$BODY" > temp_response.json
|
||||
|
||||
output_markdown() {
|
||||
if [ "$MODE" == "json" ]; then
|
||||
mv temp_response.json "$OUTPUT"
|
||||
echo "💾 Saved JSON to $OUTPUT"
|
||||
|
||||
elif [ "$MODE" == "md" ]; then
|
||||
# Write markdown header and description
|
||||
{
|
||||
echo "# 🧾 Active Subscriptions Overview"
|
||||
echo ""
|
||||
echo "This document lists all recurring subscriptions tied to this household or individual. It includes costs, renewal dates, categories, and payment methods. This record is provided as a reference for financial planning, digital legacy management, or to assist family members in case of emergencies or estate matters."
|
||||
echo ""
|
||||
echo "_Last updated: $(date +'%Y-%m-%d')_"
|
||||
echo ""
|
||||
} > "$OUTPUT"
|
||||
|
||||
if $FULL; then
|
||||
if [ "$FULL" = true ]; then
|
||||
echo "| ID | Name | Price | Currency | Next Payment | Cycle | Auto Renew | Category | Payment Method |" >> "$OUTPUT"
|
||||
echo "|----|------|-------|----------|---------------|-------|-------------|----------|----------------|" >> "$OUTPUT"
|
||||
jq -r '.subscriptions[] | [.id, .name, .price, .currency_id, .next_payment, .cycle, .auto_renew, .category_name, .payment_method_name] | @tsv' "$TMP_FILE" |
|
||||
while IFS=$'\t' read -r id name price curr next cycle renew cat pay; do
|
||||
jq -r '
|
||||
.subscriptions[] | [
|
||||
.id,
|
||||
.name,
|
||||
(.price | tostring),
|
||||
.currency_id,
|
||||
.next_payment,
|
||||
.cycle,
|
||||
.auto_renew,
|
||||
(.category_name | gsub(">"; ">") | gsub("&"; "&")),
|
||||
.payment_method_name
|
||||
] | @tsv
|
||||
' temp_response.json | while IFS=$'\t' read -r id name price curr next cycle renew cat pay; do
|
||||
echo "| $id | $name | $price | $curr | $next | $cycle | $renew | $cat | $pay |" >> "$OUTPUT"
|
||||
done
|
||||
else
|
||||
echo "| ID | Name | Price | Next Payment | Category | Payment Method |" >> "$OUTPUT"
|
||||
echo "|----|------|-------|---------------|----------|----------------|" >> "$OUTPUT"
|
||||
jq -r '.subscriptions[] | [.id, .name, .price, .next_payment, .category_name, .payment_method_name] | @tsv' "$TMP_FILE" |
|
||||
while IFS=$'\t' read -r id name price next cat pay; do
|
||||
jq -r '
|
||||
.subscriptions[] | [
|
||||
.id,
|
||||
.name,
|
||||
(.price | tostring),
|
||||
.next_payment,
|
||||
(.category_name | gsub(">"; ">") | gsub("&"; "&")),
|
||||
.payment_method_name
|
||||
] | @tsv
|
||||
' temp_response.json | while IFS=$'\t' read -r id name price next cat pay; do
|
||||
echo "| $id | $name | $price | $next | $cat | $pay |" >> "$OUTPUT"
|
||||
done
|
||||
fi
|
||||
echo "💾 Saved Markdown to $OUTPUT"
|
||||
rm -f "$TMP_FILE"
|
||||
}
|
||||
rm -f temp_response.json
|
||||
echo "💾 Saved Markdown table to $OUTPUT"
|
||||
|
||||
output_csv() {
|
||||
if $FULL; then
|
||||
echo '"id","name","price","currency_id","next_payment","cycle","auto_renew","category_name","payment_method_name"' > "$OUTPUT"
|
||||
jq -r '.subscriptions[] | [.id, .name, .price, .currency_id, .next_payment, .cycle, .auto_renew, .category_name, .payment_method_name] | @csv' "$TMP_FILE" >> "$OUTPUT"
|
||||
else
|
||||
echo '"id","name","price","next_payment","category_name","payment_method_name"' > "$OUTPUT"
|
||||
jq -r '.subscriptions[] | [.id, .name, .price, .next_payment, .category_name, .payment_method_name] | @csv' "$TMP_FILE" >> "$OUTPUT"
|
||||
if [ "$FULL" = true ]; then
|
||||
echo '"id","name","price","currency_id","next_payment","cycle","auto_renew","category_name","payment_method_name"' > "$OUTPUT"
|
||||
jq -r '
|
||||
.subscriptions[] | [
|
||||
.id,
|
||||
.name,
|
||||
.price,
|
||||
.currency_id,
|
||||
.next_payment,
|
||||
.cycle,
|
||||
.auto_renew,
|
||||
.category_name,
|
||||
.payment_method_name
|
||||
] | @csv
|
||||
' temp_response.json >> "$OUTPUT"
|
||||
else
|
||||
echo '"id","name","price","next_payment","category_name","payment_method_name"' > "$OUTPUT"
|
||||
jq -r '
|
||||
.subscriptions[] | [
|
||||
.id,
|
||||
.name,
|
||||
.price,
|
||||
.next_payment,
|
||||
.category_name,
|
||||
.payment_method_name
|
||||
] | @csv
|
||||
' temp_response.json >> "$OUTPUT"
|
||||
fi
|
||||
rm -f temp_response.json
|
||||
echo "💾 Saved CSV to $OUTPUT"
|
||||
fi
|
||||
echo "💾 Saved CSV to $OUTPUT"
|
||||
rm -f "$TMP_FILE"
|
||||
}
|
||||
|
||||
# 🏁 Main
|
||||
parse_args "$@"
|
||||
fetch_data
|
||||
|
||||
case "$MODE" in
|
||||
json) output_json ;;
|
||||
md) output_markdown ;;
|
||||
csv) output_csv ;;
|
||||
esac
|
||||
else
|
||||
echo "❌ Request failed. Response not saved."
|
||||
fi
|
||||
|
||||
Loading…
Reference in New Issue
Block a user