Beispiel #1
0
def save_votes(pdata, username):
    planet = pdata["planet"]
    planet_id = pdata["id"]
    sql = """SELECT id FROM users WHERE username = %s;"""
    data = (username,)
    user_id = db.excute_sql(sql, data, method="one")
    time = create_timestamp()
    sql1 = """INSERT INTO planetVotes (planet_id, planet_name, user_id, submission_time)
              VALUES (%s, %s, %s, %s);"""
    data1 = (planet_id, planet, user_id, time)
    db.excute_sql(sql1, data1)
Beispiel #2
0
def check_login(username, password):
    sql = """SELECT username FROM users;"""
    users = db.excute_sql(sql, method="column")
    if username in users:
        sql = """SELECT password FROM users WHERE username = %s;"""
        data = (username,)
        hahsed_pw = db.excute_sql(sql, data, method="one")
        if security.check_password_hash(hahsed_pw, password):
            return True
        return False
    return False
Beispiel #3
0
def insert_cards(board_id, title, state):
    sql = """INSERT INTO cards (board_id, title, state) VALUES (%s, %s, %s) RETURNING id;"""
    data = (board_id, title, state)
    db.excute_sql(sql, data)
Beispiel #4
0
def id_by_name(board_title):
    sql = """SELECT id FROM boards WHERE title = %s;"""
    data = (board_title, )
    board_title = db.excute_sql(sql, data, method='one')
    return board_title
Beispiel #5
0
def select_cards(boardId):
    sql = """SELECT id, title, state FROM cards WHERE board_id = %s;"""
    data = (boardId, )
    cards = db.excute_sql(sql, data, is_dict=True)
    return cards
Beispiel #6
0
def insert_board(user_id, title):
    sql = """INSERT INTO boards (user_id, title) VALUES (%s, %s) RETURNING id;"""
    data = (user_id, title)
    db.excute_sql(sql, data)
Beispiel #7
0
def get_one_board(board_id):
    sql = """SELECT id, title FROM boards WHERE id=%s;"""
    data = (board_id, )
    board = db.excute_sql(sql, data, is_dict=True)
    return board
Beispiel #8
0
def select_boards(user_id):
    sql = """SELECT id, title FROM boards WHERE user_id = %s;"""
    data = (user_id, )
    boards = db.excute_sql(sql, data, is_dict=True)
    return boards
Beispiel #9
0
def update_cards(card_id, title):
    sql = """UPDATE cards SET title = %s WHERE id = %s RETURNING id;"""
    data = (title, card_id)
    db.excute_sql(sql, data)
Beispiel #10
0
def save_hashed_pass(username, password):
    password = security.generate_password_hash(password, method='pbkdf2:sha256', salt_length=8)
    sql = """INSERT INTO users (username, password) VALUES (%s, %s) RETURNING id;"""
    data = (username, password)
    db.excute_sql(sql, data)
Beispiel #11
0
def get_id_by_username(username):
    sql = """SELECT id FROM users WHERE username = %s;"""
    data = (username,)
    result = db.excute_sql(sql, data, method='one', is_dict=True)
    return result
Beispiel #12
0
def check_username(username):
    sql = """SELECT username FROM users;"""
    users = db.excute_sql(sql, method='column')
    return False if username in users else True
Beispiel #13
0
def fetch_statistics():
    sql = """SELECT planet_name, COUNT(id) as Votes FROM planetvotes
             GROUP BY planet_name ORDER BY COUNT(id) DESC;"""
    stats = db.excute_sql(sql, method="all")
    return stats
Beispiel #14
0
def queryData():
    data = excute_sql(thounds_data, ())
    with open('record.json', 'w') as f:
        json.dump(data, f)