Refactor Script Structure and Introduce CSV Export Option #1

Open
opened 2025-04-23 08:08:55 -04:00 by nick · 0 comments
Owner

Description

Refactor wallos-fetch.sh to use a modular structure and add support for exporting subscription data in CSV format. This enhancement improves maintainability and expands the script’s utility for users who prefer spreadsheet workflows.


Proposed Behavior

The updated wallos-fetch.sh script will:

  • Organize logic into reusable functions (e.g., fetch_data, output_markdown, output_csv)
  • Allow users to select CSV output via a new --csv flag
  • Handle temporary files more securely using mktemp
  • Continue supporting Markdown (--md, default) and JSON (--json) output formats
  • Automatically name output files based on mode if no --output is provided

New CLI Options

Option Description
--csv Output subscription data as a CSV file
--full Include extended fields (e.g., currency, cycle, auto-renew) in CSV or Markdown
--output Specify a custom output filename
--version Print script version
--help Show usage instructions

CSV Output Example

With --csv --full:

"id","name","price","currency_id","next_payment","cycle","auto_renew","category_name","payment_method_name"
"1","Netflix","17.99","USD","2025-04-21","monthly","true","Entertainment","Credit Card"

With default (non---full) CSV:

"id","name","price","next_payment","category_name","payment_method_name"
"1","Netflix","17.99","2025-04-21","Entertainment","Credit Card"

Benefits

  • CSV support enables spreadsheet-friendly exports for finance tracking and custom analysis.
  • Modular script structure makes it easier to maintain and extend the script in future updates.
  • Improved output file handling and dependency checks (e.g., jq, curl) help avoid runtime surprises.
  • README was updated to reflect new options, formats, and usage examples.

Implementation Notes

  • Each output mode (json, md, csv) is encapsulated in its own function.
  • Markdown table formatting supports both basic and full display modes.
  • CSV output uses jq's @csv for proper escaping and compatibility.
  • Temporary API response is handled via mktemp, improving safety and cleanup.
#### **Description** Refactor `wallos-fetch.sh` to use a modular structure and add support for exporting subscription data in **CSV format**. This enhancement improves maintainability and expands the script’s utility for users who prefer spreadsheet workflows. --- #### **Proposed Behavior** The updated `wallos-fetch.sh` script will: - Organize logic into reusable functions (e.g., `fetch_data`, `output_markdown`, `output_csv`) - Allow users to select CSV output via a new `--csv` flag - Handle temporary files more securely using `mktemp` - Continue supporting Markdown (`--md`, default) and JSON (`--json`) output formats - Automatically name output files based on mode if no `--output` is provided --- #### **New CLI Options** | Option | Description | |---------------|-------------| | `--csv` | Output subscription data as a CSV file | | `--full` | Include extended fields (e.g., currency, cycle, auto-renew) in CSV or Markdown | | `--output` | Specify a custom output filename | | `--version` | Print script version | | `--help` | Show usage instructions | --- #### **CSV Output Example** With `--csv --full`: ```csv "id","name","price","currency_id","next_payment","cycle","auto_renew","category_name","payment_method_name" "1","Netflix","17.99","USD","2025-04-21","monthly","true","Entertainment","Credit Card" ``` With default (non-`--full`) CSV: ```csv "id","name","price","next_payment","category_name","payment_method_name" "1","Netflix","17.99","2025-04-21","Entertainment","Credit Card" ``` --- #### **Benefits** - **CSV support** enables spreadsheet-friendly exports for finance tracking and custom analysis. - **Modular script structure** makes it easier to maintain and extend the script in future updates. - Improved **output file handling** and **dependency checks** (e.g., `jq`, `curl`) help avoid runtime surprises. - README was updated to reflect new options, formats, and usage examples. --- #### **Implementation Notes** - Each output mode (`json`, `md`, `csv`) is encapsulated in its own function. - Markdown table formatting supports both basic and full display modes. - CSV output uses `jq`'s `@csv` for proper escaping and compatibility. - Temporary API response is handled via `mktemp`, improving safety and cleanup.
nick added the
enhancement
label 2025-04-23 08:08:55 -04:00
nick self-assigned this 2025-04-23 08:08:55 -04:00
nick added reference enhancement/csv-output-and-refactor 2025-04-23 08:15:53 -04:00
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: nick/wallos-fetcher#1
No description provided.