async def create_task(data: Struct): if (Task(name=data.name).exists()): raise HTTPException(status_code=422, detail="task already exist") ret = Task(data=data) if ret: return parseJson(ret) else: raise HTTPException(status_code=422, detail="can't create task")
async def update_task(id: str, item: Struct): task = Task(id) if not task.exists(): raise HTTPException(status_code=404, detail="task not found") if not task.update(item): raise HTTPException(status_code=422, detail="error update task") return parseJson(task)
async def get_all_tasks(): ret = Task().getAll() if (len(ret) == 0): raise HTTPException(status_code=404, detail="no tasks found") else: return parseJson(ret)
async def create_task(msg: discord.Message, subreddit, guildid, c: discord.Client, reddit: praw.Reddit, nsfw_url, setting): id = len(curr_tasks) + 1 task = Task(msg, id, subreddit, guildid, c, reddit, nsfw_url, setting, os.environ['UPVOTE_UNICODE'], os.environ['DOWNVOTE_UNICODE'], os.environ['WUBBLE_UNICODE'], os.environ['SAD_UNICODE']) curr_tasks.append(task) await curr_tasks[id - 1].send_submissions()
async def create_job(data: Struct): if (Job(name=data.name).exists()): raise HTTPException(status_code=422, detail="job already exist") for id in data.host_ids: if not Host(id): raise HTTPException(status_code=422, detail="host does not exist") for id in data.task_ids: if not Task(id): raise HTTPException(status_code=422, detail="task does not exist") if not Target(data.target_id): raise HTTPException(status_code=422, detail="target does not exist") j = Job(data=data) if j.getID(): return {"state": "true"} else: raise HTTPException(status_code=422, detail="can't create target")
async def delete_task(id: str): ret = Task(id).delete() if (ret == False): raise HTTPException(status_code=404, detail="task not found") else: return parseJson(ret)
async def search_for_tasks(filter: Struct): ret = Task().getAll(filter=shrinkJson(filter)) return parseJson(ret)
def prepareTasks(self): tasks = [] for id in self.getTaskIDs(): tasks.append(Task(id)) self.tasks = tasks