grocy-cli/grocy/chore.py

27 lines
797 B
Python

import logging
from grocy.conf import Configuration
from grocy.request import Request
class Chore(object):
GET_CHORES_URL_TEMPLATE = '{domain}/api/chores'
def __init__(self, id=None):
self.conf = Configuration()
self.conf.load()
self.id = id
@property
def execution_times(self):
logger = logging.getLogger('chore.execution_times')
try:
if self.id is None:
raise Exception('chore id is required')
url = self.GET_CHORES_URL_TEMPLATE.format(domain=self.conf.domain)
request = Request('get', url)
chores = request.send()
chore = next((c for c in chores if c['chore_id'] == self.id), None)
return chore
except Exception as e:
raise e