Example #1
0
def get_notification():
    value = request.form.get('value')
    print(value)
    tasks_start_time = db.session.query(Task).filter(Task.date == mytools.get_now_date_object(),
                                                     Task.start_time == mytools.get_now_time_object())
    tasks_scheduled_time = db.session.query(Task).filter(Task.date == mytools.get_now_date_object(),
                                                         Task.start_time < mytools.get_now_time_object())

    notifications = []
    for task in tasks_start_time:
        data1 = {
            'title': task.taskname,
            'body': '任务开始',
            'type': 'start'
        }
        notifications.append(data1)
    for task in tasks_scheduled_time:
        if task.start_time is not None and task.scheduled_time is not None:
            add_time = mytools.time_add_time(task.start_time, mytools.int_to_time_object(int(task.scheduled_time)))
            if add_time == mytools.get_now_time_object():
                data2 = {
                    'title': task.taskname,
                    'body': '计时结束',
                    'type': 'scheduled'
                }
                notifications.append(data2)
    print(notifications)
    if len(notifications)>0:
         if current_app.config['FLASKY_ADMIN']:
            send_email(current_app.config['FLASKY_ADMIN'], 'New User',
                   'mail/new_user', user='******')

    return jsonify(notifications=notifications)
Example #2
0
def get_notification():
    value = request.form.get('value')
    print(value)
    tasks_start_time = db.session.query(Task).filter(Task.date == mytools.get_now_date_object(),
                                                     Task.start_time == mytools.get_now_time_object())
    tasks_scheduled_time = db.session.query(Task).filter(Task.date == mytools.get_now_date_object(),
                                                         Task.start_time < mytools.get_now_time_object())

    notifications = []
    for task in tasks_start_time:
        data1 = {
            'title': task.taskname,
            'body': '任务开始',
            'type': 'start'
        }
        notifications.append(data1)
    for task in tasks_scheduled_time:
        if task.start_time is not None and task.scheduled_time is not None:
            add_time = mytools.time_add_time(task.start_time, mytools.int_to_time_object(int(task.scheduled_time)))
            if add_time == mytools.get_now_time_object():
                data2 = {
                    'title': task.taskname,
                    'body': '计时结束',
                    'type': 'scheduled'
                }
                notifications.append(data2)
    print(notifications)

    return jsonify(notifications=notifications)