class ApiService(): def __init__(self, key): self._db = Database(key) self.wordlist = Wordlist('webpath') @http('GET', '/reports/<int:id>') def reports(self, request, id): reports = self._db.get_reports(id) if reports is None: return 404, '' return 200, reports @http('GET', '/task/<int:id>') def task(self, request, id): task = self._db.get_task(id) if task is None: return 404, '' return 200, task @http('GET', '/tasks') def tasks(self, request): tasks = self._db.get_tasks() if tasks is None: return 404, '' return 200, '{}'.format(tasks) @http('GET', '/stop/<int:id>') def stop(self, request, id): pid = self._db.get_task_pid(id) if pid is None: return 404, '' os.system('kill -9 %d' % pid) return 200, 'ok'