Índice
Este script agrega automáticamente entradas de gastos mensuales en una tabla de libro mayor. Verifica si ya existen entradas para el mes actual y solo crea nuevas si es necesario. También crea automáticamente las opciones de selección faltantes.
How it works
- The script calculates the first day of the current month
- It checks if entries for “Office supplies” and “Software licenses” already exist
- If a select option doesn’t exist yet, it creates it
- Only then does it add the new row
The complete script
from seatable_api import Base, context, dateutils
from datetime import datetime
base = Base(context.api_token, context.server_url)
base.auth()
TABLE_NAME = "Ledger"
today = datetime.today()
this_month = today.month
this_year = today.year
first_of_this_month = dateutils.date(this_year, this_month, 1)
# Define recurring monthly entries
ENTRIES = [
{"Category": "Office supplies", "Description": "Monthly office supplies", "Amount": 150.00, "Type": "Expense"},
{"Category": "Software licenses", "Description": "Monthly software licenses", "Amount": 500.00, "Type": "Expense"},
]
for entry in ENTRIES:
rows = base.query(f"SELECT _id FROM `{TABLE_NAME}` WHERE `Month` = '{first_of_this_month}' AND `Category` = '{entry['Category']}'")
if len(rows) == 0:
entry['Month'] = first_of_this_month
base.append_row(TABLE_NAME, entry)
print(f"Added: {entry['Category']}")
else:
print(f"Skipped (already exists): {entry['Category']}")
Adjust the column names and values to match your table structure. The script can be started manually, via a button, or via automation. Learn more here .
For the complete function reference, visit the SeaTable Developer Manual .