From bda64575473893e129ff9804b985b7d28f4d317e Mon Sep 17 00:00:00 2001 From: lemoer Date: Fri, 27 Dec 2024 01:21:21 +0100 Subject: [PATCH] Add create_task.py --- create_task.py | 37 +++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + 2 files changed, 38 insertions(+) create mode 100644 create_task.py diff --git a/create_task.py b/create_task.py new file mode 100644 index 0000000..1cac967 --- /dev/null +++ b/create_task.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +from models import Task +import argparse +from sqlmodel import Session, SQLModel, create_engine, select +import datetime +import sys +import dateparser + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='Create a task') + parser.add_argument('name', type=str, help='Name of the task') + parser.add_argument('number_of_participants', type=int, help='Number of participants') + parser.add_argument('due', type=dateparser.parse, help='Due date of the task') + parser.add_argument('--timeout_seconds', type=int, help='Timeout in seconds (default = 1 day)', default=24*3600) + + args = parser.parse_args() + + if args.due is None: + print("Invalid due date.", file=sys.stderr) + exit(1) + + engine = create_engine("sqlite:///data.db") + SQLModel.metadata.create_all(engine) + + with Session(engine) as session: + task = Task( + name=args.name, + required_number_of_participants=args.number_of_participants, + due=args.due, + timeout=args.timeout_seconds) + + session.add(task) + session.commit() + session.refresh(task) + + print("Created: " + repr(task)) diff --git a/requirements.txt b/requirements.txt index 6ac8cd2..dbff780 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ result websockets pytest sqlmodel +dateparser