1 smartuptoolboxminimumledgerscripttemplate
robbert_founder edited this page 2025-10-21 16:40:31 +02:00
This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

title author role date parent wiki public
SmartupToolboxMinimumLedgerScriptTemplate) robbert 4_1_1 2025-10-21 2_workplace 2_workplace false

SmartupToolboxMinimumLedgerScriptTemplate)

python #!/usr/bin/env python3 """ SmartupToolboxMinimumLedgerScriptTemplate(v2.4)

Use this skeleton for any operation that reads/writesForgejoCSVledgerfiles. Implements:

  • singlesourceenvironment(importfromconfig)
  • readviafetch_csv/fetch_csv_raw
  • append/updateviaForgejoAPI(write_with_retry/append_csv_row)
  • QUOTE_ALL /legacycolumnconsistencyhandledbyforgejo_api """

import sys, os, json from datetime import datetime, timezone from pathlib import Path sys.path.append(str(Path(file).resolve().parent.parent / "common")) import forgejo_api as api import config # singlesourceconfiguration

── Utilityhelpers ──────────────────────────────────────────

def iso_now() -> str: return datetime.now(timezone.utc).isoformat().replace("+00:00","Z")

── Exampleoperation(read+append) ─────────────────────────

def sample_append(actor: str, description: str): """Example:appendoneeventtomasterevents.""" event = { "timestamp": iso_now(), "smartup_id": "0", "actor": actor, "script": Path(file).name, "event_type": "TEST_APPEND", "ref_file": "currency-ledger/example.csv", "description": description }

api.append_csv_row(
    repo=config.LEDGER_REPO,
    path="currency-ledger/master-events.csv",
    new_row=event,
    commit_msg=f"[actor={actor}][script={Path(__file__).name}]demoappend",
    actor=actor,
    branch=config.LEDGER_BRANCH
)
print("✅eventloggedtoForgejoledger.")

──Mainentrypoint──────────────────────────────────────────

if name == "main": actor = os.getenv("SMARTUP_ACTOR", input("Actor alias>")).strip() sample_append(actor, "DemonstratingstandardizedForgejowriteflow")