Exemple #1
0
 def insert_random(self, table_name):
     connection = database_helper.connect()
     cursor = database_helper.get_cursor(connection)
     random_item = randomizer.generate_random_item(database_helper.get_table_object(table_name))
     result = database_helper.insert_item(connection, cursor, table_name, random_item)
     database_helper.close_database_connection(connection, cursor)
     return result
Exemple #2
0
 def find_query(self, table_name, input, object_to_find):
     connection = database_helper.connect()
     cursor = database_helper.get_cursor(connection)
     sql = self.get_find_query(table_name, input)
     cursor.execute(sql, object_to_find)
     result = cursor.fetchall()
     database_helper.close_database_connection(connection, cursor)
     print(result)
     return result
for i in macData:
    mac_store_games.add(i[0])
for i in steamData:
    steam_games.add(i[0])

# Union all the sets together and turn into a list and sort in alph order
all_games_alph = list(set().union(gog_games, game_billet_games,
                                  humble_bundle_games, mac_store_games,
                                  steam_games))
all_games_alph.sort()
with open('game_list.json', 'w', encoding='utf-8') as f:
    json.dump(all_games_alph, f, indent=4)

# add all games to the digital ocean db
sql_select_query = """SELECT * FROM prices WHERE gameName = ?"""
digital_ocean_games_db = connect()
master_db_cursor = digital_ocean_games_db.cursor()
for i in all_games_alph:
    gogCursor.execute(sql_select_query, (i, ))
    billetCursor.execute(sql_select_query, (i, ))
    humbleCursor.execute(sql_select_query, (i, ))
    macCursor.execute(sql_select_query, (i, ))
    steamCursor.execute(sql_select_query, (i, ))

    gog_name = gogCursor.fetchone()
    mac_name = macCursor.fetchone()
    billet_name = billetCursor.fetchone()
    humble_name = humbleCursor.fetchone()
    steam_name = steamCursor.fetchone()

    insert(digital_ocean_games_db)
    # create the table
    create_table(connection, cursor)
    # compute the metrics
    metrics: list[Metric] = compute_metrics(dataset_location)
    # upload the metrics
    upload_metrics(connection, cursor, metrics)
    # Create index
    create_index(connection, cursor)
    # close the cursor
    cursor.close()
    # close the connection
    connection.close()


if __name__ == '__main__':
    """
    Main function:
        -   sys.argv[1]:    dataset location
        -   sys.argv[2]:    database name
        -   sys.argv[3]:    dataset user
        -   sys.argv[4]:    password
        -   sys.argv[5]:    port
    """
    if len(sys.argv) <= 5:
        print(
            'The dataset location, database name, user, password and port is a required input'
        )
        exit(0)
    connection = connect(sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5])
    print('Executing main...')
    main(sys.argv[1], connection)
    if not connection:
        print(
            'It is not possible to establish a connection to the postgres database, therefore the process could not continue.'
        )
        exit(1)

    # Get the cursor connection
    cursor = connection.cursor()
    # create the table
    drop_table(connection, cursor)
    # close the cursor
    cursor.close()
    # close the connection
    connection.close()


if __name__ == '__main__':
    """
    Main function:
        -   sys.argv[1]:    database name
        -   sys.argv[2]:    dataset user
        -   sys.argv[3]:    password
        -   sys.argv[4]:    port
    """
    if len(sys.argv) <= 4:
        print('The database name, user, password and port is a required input')
        exit(0)
    connection = connect(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
    print('Executing main...')
    main(connection)
Exemple #6
0
 def select_all(self, table_name):
     connection = database_helper.connect()
     cursor = database_helper.get_cursor(connection)
     result = database_helper.select_all(connection, cursor, table_name)
     database_helper.close_database_connection(connection, cursor)
     return result
Exemple #7
0
 def query(self, sql_query):
     connection = database_helper.connect()
     cursor = database_helper.get_cursor(connection)
     result = database_helper.query(connection, cursor, sql_query)
     database_helper.close_database_connection(connection, cursor)
     return result
Exemple #8
0
 def update_item(self, table_name, object_to_update, new_object):
     connection = database_helper.connect()
     cursor = database_helper.get_cursor(connection)
     result = database_helper.update_item(connection, cursor, table_name, object_to_update, new_object)
     database_helper.close_database_connection(connection, cursor)
     return result
Exemple #9
0
 def delete_item(self, table_name, object_to_delete):
     connection = database_helper.connect()
     cursor = database_helper.get_cursor(connection)
     result = database_helper.delete_item(connection, cursor, table_name, object_to_delete)
     database_helper.close_database_connection(connection, cursor)
     return result
Exemple #10
0
 def select_item(self, table_name, obj_to_find):
     connection = database_helper.connect()
     cursor = database_helper.get_cursor(connection)
     result = database_helper.select_item(connection, cursor, table_name, obj_to_find)
     database_helper.close_database_connection(connection, cursor)
     return result
Exemple #11
0
 def insert_item(self, obj, table_name):
     connection = database_helper.connect()
     cursor = database_helper.get_cursor(connection)
     result = database_helper.insert_item(connection, cursor, table_name, obj)
     database_helper.close_database_connection(connection, cursor)
     return result