Skip to content

earnings.1m.py.rtf: #2121

@taysonspitzer-oss

Description

@taysonspitzer-oss

fao @ -
{\rtf1\ansi\ansicpg1252\cocoartf2761
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
{*\expandedcolortbl;;}
\margl1440\margr1440\vieww11520\viewh8400\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0

\f0\fs24 \cf0 #!/usr/bin/env python3\

<xbar.title>Earnings Tracker</xbar.title>\

<xbar.version>v1.1</xbar.version>\

<xbar.author>You</xbar.author>\

<xbar.desc>Tracks live work earnings at $25/hr + $0.10 per task</xbar.desc>\


import os, time, json, sys
\

File to store data\

DATA_FILE = os.path.expanduser("~/.xbar_earnings.json")
\

Settings\

HOURLY_RATE = 25.0
TASK_RATE = 0.10
\

Load saved data\

if os.path.exists(DATA_FILE):
with open(DATA_FILE, "r") as f:
data = json.load(f)
else:
data = {"start_time": None, "tasks": 0}

def save():
with open(DATA_FILE, "w") as f:
json.dump(data, f)

def elapsed_hours():
if data["start_time"] is None:
return 0
return (time.time() - data["start_time"]) / 3600

def earnings():
return elapsed_hours() * HOURLY_RATE + data["tasks"] * TASK_RATE

def format_time(seconds):
m, s = divmod(int(seconds), 60)
h, m = divmod(m, 60)
return f"{h}h {m}m"
\

Main Display (menu bar text)\

elapsed_seconds = (time.time() - data["start_time"]) if data["start_time"] else 0
print(f"\uc0\u55357 \u56501 ${earnings():.2f} ({format_time(elapsed_seconds)}, {data['tasks']} tasks)")
\

Dropdown menu\

print("---")
print("\uc0\u9654 \u65039 Start | bash=/usr/bin/env python3 param1="+file+" param2=start terminal=false refresh=true")
print("\uc0\u9208 \u65039 Stop | bash=/usr/bin/env python3 param1="+file+" param2=stop terminal=false refresh=true")
print("\uc0\u10133 Add Task | bash=/usr/bin/env python3 param1="+file+" param2=task terminal=false refresh=true")
print("\uc0\u55357 \u56580 Reset | bash=/usr/bin/env python3 param1="+file+" param2=reset terminal=false refresh=true")
\

Handle actions\

if len(sys.argv) > 1:
action = sys.argv[1]
if action == "start":
data["start_time"] = time.time()
elif action == "stop":
data["start_time"] = None
elif action == "task":
data["tasks"] += 1
elif action == "reset":
data = {"start_time": None, "tasks": 0}
save()}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions