jhrcook / SwiftBar-Plugins

My SwiftBar plugins.

Home Page:https://github.com/swiftbar/SwiftBar

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use getter for number of coffee uses

jhrcook opened this issue · comments

Currently, the plugin pulls down all of the uses information for the day and then returns the length of the list. It would be faster and easier to just query the number of uses for the day directly.

def get_todays_uses() -> List[CoffeeUse]:
try:
response = requests.get(
api_url + f"uses/?n_last=20&since={get_today_formatted_datetime()}"
)
return [CoffeeUse(key=k, **i) for k, i in response.json().items()]
except Exception as err:
print(f"error: {err}")
return []
def get_number_of_cups_today() -> int:
cups: List[CoffeeUse] = get_todays_uses()
return len(cups)