Add airport address alias to log-work-expense skill

This commit is contained in:
Connor Rhodes 2026-05-20 17:52:08 -05:00
parent bda05feab1
commit f473c09a26
2 changed files with 50 additions and 4 deletions

View file

@ -2,13 +2,15 @@
"""Log work expenses to MongoDB (wip.work_expenses).
Usage:
python log_expense.py <type> <account> <date> <note> <s2_url_1> [s2_url_2]
python log_expense.py <type> <account> <date> <note> <s2_url_1> [s2_url_2] [--route stop1,stop2,...]
type: "meal" or "mileage"
account: e.g. "LTISD"
date: YYYY-MM-DD
note: free-text context (quote if it has spaces)
s2_url: one or more S2 URLs of uploaded files
--route: comma-separated list of stops (mileage only). Home address is
automatically prepended and appended.
Rules enforced:
- meal: exactly 1 file per invocation
@ -16,12 +18,32 @@ Rules enforced:
"""
import sys
from datetime import datetime
from pymongo import MongoClient
HOME = "11600 Minda Cir Austin, TX 78758"
ALIASES = {
"airport": "3201 Presidential Blvd, Austin, TX 78719",
"aus": "3201 Presidential Blvd, Austin, TX 78719",
}
def main():
args = sys.argv[1:]
route_stops = None
if "--route" in args:
idx = args.index("--route")
args.pop(idx)
if idx >= len(args):
print("Error: --route requires a value")
sys.exit(1)
route_val = args.pop(idx)
route_stops = [s.strip() for s in route_val.split("|") if s.strip()]
route_stops = [ALIASES.get(s.lower(), s) for s in route_stops]
route_stops = [HOME] + route_stops + [HOME]
if len(args) < 5:
print("Usage: log_expense.py <type> <account> <date> <note> <s2_url_1> [s2_url_2]")
print('Usage: log_expense.py <type> <account> <date> <note> <s2_url_1> [s2_url_2] [--route stop1|stop2]')
sys.exit(1)
exp_type = args[0]
@ -42,19 +64,26 @@ def main():
print(f"Error: mileage entries must have exactly 2 files (start + end odometer), got {len(files)}")
sys.exit(1)
if route_stops is not None and exp_type != "mileage":
print("Error: --route is only valid for mileage entries")
sys.exit(1)
client = MongoClient("mongodb://root:3wwfoUjyk2E2zWELXFlLuHqfw1ALlOp4pb2H5Vq3TImbMIHL2h1u8Jej2mjzCPl@docdb.connorrhodes.com:35563?tls=true&tlsAllowInvalidCertificates=true")
db = client["wip"]
col = db["work_expenses"]
doc = {
"files": files,
"date": date,
"date": datetime.strptime(date, "%Y-%m-%d"),
"type": exp_type,
"account": account,
"note": note,
"status": "todo"
}
if route_stops is not None:
doc["route"] = route_stops
result = col.insert_one(doc)
print(f"Inserted {exp_type} for {account} on {date}: {result.inserted_id}")