IMDB到SQLite:如何创建表并将imdb数据插入sqlite数据库?

时间:2019-01-04 04:31:33

标签: database sqlite imdbpy

我正在一个项目中,我希望将我从here下载到sqlite数据库中的精选IMDB文件(文件格式在* .list中)。不幸的是,我无法解决此问题。我能够创建数据库,但是不能用IMDB数据将表制成表格。

我一直关注的文档是here.,到目前为止,我已经创建了一个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 :(得分:0)

我找到了解决方法!

<div class="block-container grid-3-cols_wrapper">
   <!-- Row 1 -->
   <div class="has-3-columns">
      <!-- Col 1 -->
      <div class="block-column">
         <div><img src="..." alt=""></div>
      </div>

      <!-- Col 2 -->
      <div class="block-column">
         <div><img src="..." alt=""></div>
      </div>

      <!-- Col 3 -->
      <div class="block-column">
         <div><img src="..." alt=""></div>
      </div>

   <!-- Row 2 -->
   <div class="has-3-columns">
      <!-- Col 1 -->
      <div class="block-column">
         <div><img src="..." alt=""></div>
      </div>

      <!-- Col 2 -->
      <div class="block-column">
         <div><img src="..." alt=""></div>
      </div>

      <!-- Col 3 -->
      <div class="block-column">
         <div><img src="..." alt=""></div>
      </div>
</div>

然后

pip install imdb-sqlite

这里是link