Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use getter for number of coffee uses #9

Closed
jhrcook opened this issue Mar 16, 2021 · 0 comments
Closed

Use getter for number of coffee uses #9

jhrcook opened this issue Mar 16, 2021 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@jhrcook
Copy link
Owner

jhrcook commented Mar 16, 2021

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)

@jhrcook jhrcook added the enhancement New feature or request label Mar 16, 2021
@jhrcook jhrcook self-assigned this Mar 16, 2021
@jhrcook jhrcook closed this as completed Mar 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant