IMDB для SQLite: Как создать таблицу и вставить данные IMDB в базу данных SQLite? - PullRequest
0 голосов
/ 04 января 2019

Я работаю над проектом, в котором я хочу выбрать файлы IMDB (формат файлов в * .list), которые я скачал из здесь в базу данных sqlite.К сожалению, я не могу решить эту проблему.Я могу создать базу данных, но не могу табулировать таблицу с данными IMDB.

Документация, за которой я следовал, здесь . До сих пор я создал таблицу sqlite, но она не будет заполняться.

import sqlite3
from sqlite3 import Error

def create_connection(db_file):
    """ create a database connection to the SQLite database
        specified by db_file
    :param db_file: database file
    :return: Connection object or None
    """
    try:
        conn = sqlite3.connect(db_file)
        return conn
    except Error as e:
        print(e)

    return None

def create_table(conn, create_table_sql):
    """    create a table from the create_table_sql statement
    :param conn: Connection object
    :param create_table_sql: a CREATE TABLE statement
    :return:

    """
    try:
        c = conn.cursor()
        c.execute(create_table_sql)
    except Error as e:
        print(e)

def main():
    database = "/Users/Erudition/Desktop/imdb_database/sqldatabase.db"

    sql_create_tile_akas = """ CREATE TABLE IF NOT EXISTS title (
                                        titleid text PRIMARY KEY,
                                        ordering integer NOT NULL,
                                        title text,
                                        region text,
                                        language text NOT NULL,
                                        types text NOT NULL,
                                        attributes text NOT NULL,
                                        isOriginalTitle integer NOT NULL

                                    ); """

    conn = create_connection(database)
    if conn is not None:
        # create projects table
        create_table(conn, sql_create_tile_akas)

    else:
        print("Error! cannot create the database connection.")

if __name__ == '__main__':
      main()

В терминале я ввожу

 imdbpy2sql.py -d /Users/Erudition/Desktop/imdb_database/aka-titles.list/  
 -u sqlite:///sqldatabase.db'''

Ожидаемый вывод - таблица sqlite со всеми заполненными строками.Вместо этого я получаю несколько таблиц sqlite без заполнения.

Выход терминала:

WARNING The file will be skipped, and the contained
WARNING information will NOT be stored in the database.
WARNING Complete error:  [Errno 20] Not a directory: 
'/Users/Erudition/Desktop/imdb_database/aka-titles.list/complete- 
cast.list.gz'
WARNING WARNING WARNING
WARNING unable to read the "/Users/Erudition/Desktop/imdb_database/aka- 
titles.list/complete-crew.list.gz" file.
WARNING The file will be skipped, and the contained
WARNING information will NOT be stored in the database.
WARNING Complete error:  [Errno 20] Not a directory: 
'/Users/Erudition/Desktop/imdb_database/aka-titles.list/complete- 
crew.list.gz'

1 Ответ

0 голосов
/ 04 января 2019

Я нашел решение!

pip install imdb-sqlite

Тогда

imdb-sqlite

Вот ссылка

...