Esempio n. 1
0
def update_user(user: User, conn: MySQLdb.Connection, commit=True):
    cursor = conn.cursor()
    cursor.execute(
        "UPDATE users SET name=%s,email=%s,notification_via=%s,lang=%s WHERE chat_id=%s",
        (user.name, user.email, user.notification_via, user.lang),
    )
    if commit:
        conn.commit()
    cursor.close()
Esempio n. 2
0
def get_or_save_user(chat_id: str, username: str, email: str,
                     notification_via: str, conn: MySQLdb.Connection):
    cursor = conn.cursor()
    cursor.execute(
        "IF NOT EXISTS (SELECT id FROM users WHERE chat_id=%s) THEN "
        "INSERT INTO users(chat_id, name, email, notification_via) VALUES(%s, %s, %s, %s);"
        "END IF;", (chat_id, chat_id, username, email, notification_via))
    conn.commit()
    return get_user(conn, chat_id=chat_id)
Esempio n. 3
0
def insert_train_in_db(train: Train, conn: MySQLdb.Connection, commit=True):
    if train.depart_date >= datetime.now() or train.check_daily:
        cursor = conn.cursor()
        cursor.execute(
            "INSERT INTO monitoring (train, station, departDate, user, check_daily, check_interval, coach, seat) "
            "VALUES(%s, %s, %s, %s, %s, %s, %s, %s)",
            (train.code, train.depart_stat, train.depart_date, train.user,
             train.check_daily, train.check_interval, train.coach, train.seat))
        if commit:
            conn.commit()
        cursor.close()
    else:
        raise TrainInPastError(
            f"Train depart date: {train.depart_date}; now: {datetime.now()}")
Esempio n. 4
0
def update_user_lang(conn: MySQLdb.Connection,
                     user_id="",
                     chat_id="",
                     lang="it",
                     commit=True):
    cursor = conn.cursor()
    if user_id:
        cursor.execute("UPDATE users SET lang=%s WHERE id=%s", (lang, user_id))
    else:
        cursor.execute("UPDATE users SET lang=%s WHERE chat_id=%s",
                       (lang, chat_id))

    if commit:
        conn.commit()
    cursor.close()
Esempio n. 5
0
def store_feedback(feedback: str, chat_id: str, conn: MySQLdb.Connection):
    cursor = conn.cursor()
    cursor.execute("INSERT INTO feedbacks(user, feedback) VALUES(%s, %s)",
                   (chat_id, feedback))
    conn.commit()
    cursor.close()
Esempio n. 6
0
def update_train_checked(pk: int, conn: MySQLdb.Connection):
    cursor = conn.cursor()
    cursor.execute("UPDATE monitoring set checked = checked + 1 WHERE id=%s",
                   (pk, ))
    conn.commit()
    cursor.close()
Esempio n. 7
0
def delete_train(pk: int, conn: MySQLdb.Connection):
    cursor = conn.cursor()
    cursor.execute("DELETE FROM monitoring WHERE id=%s", (pk, ))
    conn.commit()
    cursor.close()