def do(self): user = User(self._app.db, self._template) user.chat_id = ''.join(filter(str.isdigit,str(self.message['message']['chat']['id']))) conterQuery = { 'chat_id' : self.message['message']['chat']['id'], 'text' : '' } yield user.selectThis() logging.debug("startAction.do():gotted user from db is %s " % str(user.chat_id)) if user.game_id != '': conterQuery['text'] = 'You are already registered!!! Then task' else: user.game_id = 3 yield user.insertThis() conterQuery['text'] = 'You will be registered in system, task will be sended in seconds!!!' game = Game(self._app.db, self._template) game.id = user.game_id yield game.selectThis() task = Task(self._app.db,self._template) task.id = user.getTask() if task.id is False: conterQuery['text'] = "Task list is empty, may be game over???" raise tornado.gen.Return(conterQuery) yield task.selectThis() conterQuery['text'] = task.text raise tornado.gen.Return(conterQuery)
def get_tasks_for_user(): incoming = request.get_json() return jsonify(tasks=[ i.serialize for i in Task.get_tasks_for_user(incoming["user_id"]).all() ])
def cmd_planifier(msg): ''' Commande pour la planification d’un message récuurrent. Utilise le context pour la réponse. Ex : - Vous: /planifier - Lui : À qu’elle heure ? - Vous : 10h - Lui : Trés bien … planification de « commande » à 10h ou : - Vous /planifier 10h - Lui : Trés bien … planification de « commande » à 10h ''' previous_text = get_last_message(msg) if previous_text and "planifier" not in previous_text: heure, minute = extract_hours_minutes(msg["query"]) if heure: task = Task(username_or_channel(msg), "{0}:{1}".format(heure, minute), previous_text) db_session.add(task) db_session.commit() return "Parfait ! Vous allez recevoir automatiquement « {0} » tous les jours à {1}h{2}".format( previous_text, heure, minute) else: mark_for_awaiting_response(username_or_channel(msg), "planifier") return "À qu’elle heure voulez vous planifier l’envoi automatique de « {0} » ?".format( previous_text) else: return "Désolé, je ne peu pas planifier autre chose qu’une commande."
def create_task(): title: str = request.form["title"] limit_at: datetime = datetime(request.form["limit_at"]) category_id: int = int(request.form["category_id"]) task = Task(title=title, limit_at=limit_at, category_id=category_id) dbsession.add(task) dbsession.commit() return redirect(url_for('show_tasks'))
def submit_task(): incoming = request.get_json() task = Task(task=incoming["task"], user_id=incoming["user_id"], status=incoming["status"]) db.session.add(task) try: db.session.commit() except IntegrityError: return jsonify(message="Error submitting task"), 409 return jsonify(success=True)
def do(self): user = User(self._app.db, self._template) user.chat_id = ''.join( filter(str.isdigit, str(self.message['message']['chat']['id']))) conterQuery = { 'chat_id': self.message['message']['chat']['id'], 'text': '' } yield user.selectThis() logging.debug("startAction.do():gotted user from db is %s " % str(user.chat_id)) if user.game_id != '': conterQuery['text'] = 'You are already registered!!! Then task' else: user.game_id = 3 yield user.insertThis() conterQuery[ 'text'] = 'You will be registered in system, task will be sended in seconds!!!' game = Game(self._app.db, self._template) game.id = user.game_id yield game.selectThis() task = Task(self._app.db, self._template) task.id = user.getTask() if task.id is False: conterQuery['text'] = "Task list is empty, may be game over???" raise tornado.gen.Return(conterQuery) yield task.selectThis() conterQuery['text'] = task.text raise tornado.gen.Return(conterQuery)
def get_user(): return jsonify(result=g.current_user, tasks=Task.get_latest_tasks())
def do(self): user = User(self._app.db,self._template) user.chat_id = ''.join(filter(str.isdigit,str(self.message['message']['chat']['id']))) find = re.match("/answer[ ]*(.+)", str(self.message['message']['text']), re.IGNORECASE) conterQuery = { 'chat_id' : self.message['message']['chat']['id'], 'text' : '' } if find is None: conterQuery['text'] = "There is no answer!" logging.warning("answerAction.do(): User's answer don't contain text: \n %s", (self.message['message']['text'])) raise tornado.gen.Return(conterQuery) answer = find.groups()[0] yield user.selectThis() logging.debug("answerAction.do(): gotted user from db is %s " % str(user.chat_id)) if (user.game_id == ''): conterQuery['text'] = 'You not take a competition in game, please register by typing "/start" or "/help" for help' logging.warning("answerAction.do(): user dont have permissions to game \n user - %s " % str(user.chat_id)) raise tornado.gen.Return(conterQuery) game = Game(self._app.db,self._template) game.id = user.game_id yield game.selectThis() task = Task(self._app.db,self._template) task.id = user.getTask() if not (task.id): logging.error("answerAction.do(): task id is not defined for user %s " % str(user.chat_id)) conterQuery['text'] = "we don't have any tasks for you, please send /start or /help" raise tornado.gen.Return(conterQuery) yield task.selectThis() if not (task.compareAnswer(answer)): logging.info("answerAction.do(): User sended wrong answer: \n user %s, task.answer %s, answer %s", (user.chat_id, task.answer, answer)) conterQuery['text'] = "This is wrong answer! Try another" raise tornado.gen.Return(conterQuery) currentTask = yield user.changeTask() if not currentTask is False: if currentTask is True: self._message['message']['text'] = "/finish" logging.info("answerAction.do(): User will be redirrected to /finish\n changeTask returned %s" % currentTask) else: self._message['message']['text'] = "/start" logging.info("answerAction.do(): User will be redirrected to /start\n changeTask returned %s" % currentTask) logging.info("answerAction.do(): User sended right answer and will take new task \n user %s, task.answer %s, answer %s" % (user.chat_id, task.answer, answer)) conterQuery['text'] = "Thats right!!" tornado.gen.Task(self._app.sendLocalMessage,self._message,2) else: conterQuery['text'] = "Something wrong, please contact administrator" raise tornado.gen.Return(conterQuery)
def do(self): user = User(self._app.db, self._template) user.chat_id = ''.join( filter(str.isdigit, str(self.message['message']['chat']['id']))) find = re.match("/answer[ ]*(.+)", str(self.message['message']['text']), re.IGNORECASE) conterQuery = { 'chat_id': self.message['message']['chat']['id'], 'text': '' } if find is None: conterQuery['text'] = "There is no answer!" logging.warning( "answerAction.do(): User's answer don't contain text: \n %s", (self.message['message']['text'])) raise tornado.gen.Return(conterQuery) answer = find.groups()[0] yield user.selectThis() logging.debug("answerAction.do(): gotted user from db is %s " % str(user.chat_id)) if (user.game_id == ''): conterQuery[ 'text'] = 'You not take a competition in game, please register by typing "/start" or "/help" for help' logging.warning( "answerAction.do(): user dont have permissions to game \n user - %s " % str(user.chat_id)) raise tornado.gen.Return(conterQuery) game = Game(self._app.db, self._template) game.id = user.game_id yield game.selectThis() task = Task(self._app.db, self._template) task.id = user.getTask() if not (task.id): logging.error( "answerAction.do(): task id is not defined for user %s " % str(user.chat_id)) conterQuery[ 'text'] = "we don't have any tasks for you, please send /start or /help" raise tornado.gen.Return(conterQuery) yield task.selectThis() if not (task.compareAnswer(answer)): logging.info( "answerAction.do(): User sended wrong answer: \n user %s, task.answer %s, answer %s", (user.chat_id, task.answer, answer)) conterQuery['text'] = "This is wrong answer! Try another" raise tornado.gen.Return(conterQuery) currentTask = yield user.changeTask() if not currentTask is False: if currentTask is True: self._message['message']['text'] = "/finish" logging.info( "answerAction.do(): User will be redirrected to /finish\n changeTask returned %s" % currentTask) else: self._message['message']['text'] = "/start" logging.info( "answerAction.do(): User will be redirrected to /start\n changeTask returned %s" % currentTask) logging.info( "answerAction.do(): User sended right answer and will take new task \n user %s, task.answer %s, answer %s" % (user.chat_id, task.answer, answer)) conterQuery['text'] = "Thats right!!" tornado.gen.Task(self._app.sendLocalMessage, self._message, 2) else: conterQuery[ 'text'] = "Something wrong, please contact administrator" raise tornado.gen.Return(conterQuery)
import psycopg2 from models.models import Task db = psycopg2.connect("user=postgres password=postgres dbname=qa_bot host=localhost port=5432") cursor = db.cursor() task = Task() task.images = "" task.text = "simple task text" task.topic = "simple topic" task.answer = "followed answer" cursor.execute(task.insertThis()) db.commit() db.close()
import psycopg2 from models.models import Task db = psycopg2.connect( "user=postgres password=postgres dbname=qa_bot host=localhost port=5432") cursor = db.cursor() task = Task() task.images = "" task.text = "simple task text" task.topic = "simple topic" task.answer = "followed answer" cursor.execute(task.insertThis()) db.commit() db.close()