lab-signal-bot/create_task.py

38 lines
1.2 KiB
Python
Raw Normal View History

2024-12-27 01:21:21 +01:00
#!/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))