Example #1
0
def main():
    print('This program analyzes yout Google Fit data.')
    print(
        'Make sure you have the file \'Daily Summaries.csv\' in the same directory.'
    )
    user_input = input('Do you want to start? Y/N \n')
    if user_input == 'Y' or 'y':

        print('Type (enter number):\n')
        print('1 - Speed')
        print('2 - Activities time')
        print('3 - Steps')

        user_input = input()
        user_date = input('Please enter date in format YYY-MM-DD\n')
        validate_date(user_date)

        if user_input == '1':
            graph_speed = Analyze(user_date)
            graph_speed.speed()

        elif user_input == '2':
            bar_time = Analyze(user_date)
            bar_time.activity_time()

        elif user_input == '3':
            step_bar = Analyze(user_date)
            step_bar.steps()

    else:
        exit
Example #2
0
def edit_post(post_id):
    """
    Function for editing existing post.
    """
    if request.method == 'POST':
        day = int(request.form['day'])
        month = int(request.form['month'])
        year = int(request.form['year'])
        if validate_date(day, month, year):
            date = str(day) + "." + str(month) + "." + str(year)
            g.db.edit_post(
                    post_id[0],
                    request.form['title'],
                    date,
                    request.form['text'])
            return redirect(url_for('admin.show_admin_posts'))
        else:
            session['notification_active'] = True
            session['notification_title'] = "Date error!"
            session['notification_color'] = "alert"
            session['notification_description'] = "Please check date form\
                twice."
    post = g.db.get_post_by_id(post_id)
    date = re.split(r'\.', post['date'])
    post['day'] = date[0]
    post['month'] = date[1]
    post['year'] = date[2]
    return render_template('admin/edit_post.djhtml', post=post)
Example #3
0
def show_new_post_forms():
    """
    Function for "host/admin/posts/new".
    Creator of new posts.
    """
    if request.method == 'POST':
        day = int(request.form['day'])
        month = int(request.form['month'])
        year = int(request.form['year'])
        if validate_date(day, month, year):
            date = str(day) + "." + str(month) + "." + str(year)
            g.db.add_post(
                request.form['title'],
                date,
                request.form['text'])
            session['notification_active'] = True
            session['notification_title'] = "Post created!"
            session['notification_description'] = "Post successfully created."
            session['notification_color'] = "success"
            return redirect(url_for('admin.show_admin_posts'))
        else:
            session['notification_active'] = True
            session['notification_title'] = "Date error!"
            session['notification_color'] = "alert"
            session['notification_description'] = "Please check date form\
                twice."
    return render_template('admin/new_post.djhtml')
Example #4
0
def handle_text_message(event):
    conn = model.Conn()

    line_user_id = event.source.user_id
    text = event.message.text

    session_bytes = redis.get(line_user_id)
    session = {}
    if session_bytes is not None:
        session = json.loads(session_bytes.decode("utf-8"))

    print('\n\n\nHERE, request event:', event)
    print("\n\n\nHERE, session:", session)

    if session == {}:
        print("\n\n\nHERE # USER PERTAMA KALI BUKA")
        redis.set(line_user_id, json.dumps({'status': 'login'}))

        remove_rich_menu(line_user_id)

        line_bot_api.reply_message(event.reply_token, [
            TextMessage(text=constant.WELCOME_APP),
            TextMessage(text=constant.LOGIN)
        ])
    else:
        if 'login' in session['status']:
            print("\n\n\nHERE # PROSES LOGIN")
            text = text.replace(' ', '')
            texts = text.split('-')

            if len(texts) != 2:  # VALIDASI LOGIN GAGAL
                line_bot_api.reply_message(event.reply_token, [
                    TextMessage(text=constant.LOGIN_VALIDATION_FAIL),
                    TextMessage(text=constant.LOGIN)
                ])
            else:
                nisn = texts[0]
                dob = texts[1]
                if util.validate_date(dob, '%d%m%Y'):
                    query_select = 'SELECT * FROM student WHERE nisn = %s AND dob = %s LIMIT 1'
                    conn.query(
                        query_select,
                        (nisn, util.convert_date(dob, '%d%m%Y', '%Y-%m-%d')))
                    row = conn.cursor.fetchone()
                    if row == None:  # LOGIN GAGAL
                        line_bot_api.reply_message(event.reply_token, [
                            TextMessage(text=constant.LOGIN_FAIL),
                            TextMessage(text=constant.LOGIN)
                        ])
                    else:
                        print("\n\n\nHERE # LOGIN BERHASIL")

                        # create rich menu
                        rich_menu = create_rich_menu(line_user_id)

                        line_bot_api.link_rich_menu_to_user(
                            line_user_id, rich_menu['home'])
                        redis.set(
                            line_user_id,
                            json.dumps({
                                'user_id': row['id'],
                                'nisn': row['nisn'],
                                'name': row['name'],
                                'class_id': row['class_id'],
                                'status': 'home',
                                'rich_menu': rich_menu
                            }))

                        line_bot_api.reply_message(event.reply_token, [
                            TextMessage(text=constant.WELCOME_HOME %
                                        (row['name']), )
                        ])

                else:
                    print("\n\n\nHERE # VALIDASI LOGIN GAGAL")
                    line_bot_api.reply_message(event.reply_token, [
                        TextMessage(text=constant.LOGIN_VALIDATION_FAIL),
                        TextMessage(text=constant.LOGIN)
                    ])
        else:
            # to handle save reply on discussion
            if 'material_discussion' in session:
                query_insert_discussion = 'INSERT INTO class_discussion_detail (class_discussion_id, description, user_id, student_id, date) VALUES (%s, %s, %s, %s, NOW())'
                insert_discussion = (
                    session['material_discussion']['class_discussion_id'],
                    text, session['material_discussion']['user_id'],
                    session['material_discussion']['student_id'])
                conn.query(query_insert_discussion, insert_discussion)
                conn.commit()

                redis.set(
                    line_user_id,
                    json.dumps({
                        'user_id': session['user_id'],
                        'nisn': session['nisn'],
                        'name': session['name'],
                        'class_id': session['class_id'],
                        'status': 'home',
                        'rich_menu': session['rich_menu']
                    }))

                flex_messages = []
                flex_message_material_topic = show_material_topic(
                    event, conn, session['material_discussion'])
                flex_messages.append(flex_message_material_topic)

                line_bot_api.reply_message(event.reply_token, flex_messages)