Add create_task.py

This commit is contained in:
lemoer 2024-12-27 01:21:21 +01:00
parent 7ec74d859f
commit bda6457547
2 changed files with 38 additions and 0 deletions

37
create_task.py Normal file
View File

@ -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))

View File

@ -4,3 +4,4 @@ result
websockets
pytest
sqlmodel
dateparser