import simplematrixbotlib as botlib
-from goals.db import Data
+from goals.db import Data, pretty_print
SERVER = os.environ.get('MATRIX_SERVER')
goal_id = int(match.args()[1])
logger.debug(f'Searching for goal {goal_id}...')
goal,tasks = Data().get_goal(goal_id)
-
- results = []
- results.append(f' ## {goal}')
- for task in tasks:
- if(task.complete_date):
- results.append(f' - [x] {task}')
- else:
- results.append(f' - [ ] {task}')
+ results = pretty_print(goal, tasks)
return results
- if match.command('done'):
+ if match.command('goal-done'):
goal_id = int(match.args()[1])
logger.debug(f'Searching for goal {goal_id}...')
- result = Data().complete_goal(goal_id)
- return [result]
+ Data().complete_goal(goal_id)
+ goal,tasks = Data().get_goal(goal_id)
+ results = pretty_print(goal, tasks)
+ return results
+
+ if match.command('done'):
+ task_id = int(match.args()[1])
+ goal_id = Data().complete_task(task_id)
+ goal,tasks = Data().get_goal(goal_id)
+ results = pretty_print(goal, tasks)
+ return results
+
return __doc__
def __str__(self):
return f'{self.name} ({self.id})'
+
+def pretty_print(goal, tasks):
+ results = []
+ results.append(f' ## {goal}')
+ for task in tasks:
+ if(task.complete_date):
+ results.append(f' - [x] {task}')
+ else:
+ results.append(f' - [ ] {task}')
+ return results
+
+
class Data():
def __init__(self, db_file = DB_FILE):
self.file = db_file
goal = session.exec(cmd).first()
goal.complete_date = dt.today()
session.commit()
- return self.get_goal(id)
def complete_task(self, id):
- pass
+ with Session(self.engine) as session:
+ cmd = select(Task).where(Task.id == id)
+ task = session.exec(cmd).first()
+ task.complete_date = dt.today()
+ goal_id = task.goal_id
+ session.commit()
+ return goal_id
def add_with_name(self, cls, name):
id = -1