Beispiel #1
0
def create_db_hiscore():
    with MySQL.UseDatabase(config) as cursor:
        cursor.execute("""drop table if exists hiscore;""")
        cursor.execute(
            """create table hiscore(hiscore_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, score_amt INT NOT NULL, player_sn varchar(16) NOT NULL);"""
        )
    print("Table hiscore created!")
Beispiel #2
0
def check_guess(guess):
    with MySQL.UseDatabase(config) as cursor:
        cursor.execute("""SELECT * from dict where word_sn = %s;""", (guess, ))
        if len(cursor.fetchall()) == 0:
            return False
        else:
            return True
Beispiel #3
0
def create_db_dict():
    with MySQL.UseDatabase(config) as cursor:
        cursor.execute("""drop table if exists dict;""")
        cursor.execute(
            """create table dict(dict_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, word_sn VARCHAR(24));"""
        )
        print("Table dict created!")
Beispiel #4
0
def hiscore_to_db():
    if check_score_list():
        with MySQL.UseDatabase(config) as cursor:
            for item in scorelist:
                cursor.execute(
                    """INSERT INTO hiscore(player_sn, score_amt) VALUES(%s, %s);""",
                    (item[0], item[1]))
    print("Scores inserted into database!")
Beispiel #5
0
def dict_to_db():
    if check_dict_lists():
        with MySQL.UseDatabase(config) as cursor:
            #All short words of guesslist
            for guess in guesslist:
                if len(guess) < 7:
                    cursor.execute("""INSERT INTO dict(word_sn) VALUES(%s);""",
                                   (guess, ))
            #Any other words in sourcelist (filtered for unwinnable)
            for source in sourcelist:
                cursor.execute("""INSERT INTO dict(word_sn) VALUES(%s);""",
                               (source, ))
    print("Dictionaries inserted into database!")
Beispiel #6
0
def get_top_ten():
    with MySQL.UseDatabase(config) as cursor:
        cursor.execute(
            """SELECT player_sn, score_amt FROM hiscore ORDER BY score_amt DESC, hiscore_id ASC LIMIT 10;"""
        )
        return cursor.fetchall()
Beispiel #7
0
def insert_hiscore(name, score):
    with MySQL.UseDatabase(config) as cursor:
        cursor.execute(
            """INSERT INTO hiscore(player_sn, score_amt) VALUES(%s, %s);""",
            (str(name), int(score)))
Beispiel #8
0
def get_random_source():
    with MySQL.UseDatabase(config) as cursor:
        cursor.execute(
            """SELECT word_sn FROM dict WHERE CHAR_LENGTH(word_sn) >= 7 ORDER BY RAND() LIMIT 1;"""
        )
        return cursor.fetchall()[0][0]