database - IMDB 到 SQLite:如何创建表并将 imdb 数据插入 sqlite 数据库?
问题描述
我正在做一个项目,我想要从这里下载到 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'
解决方案
推荐阅读
- reactjs - 访问样式化组件 nth-child 时出现问题
- d3.js - d3.line 不为折线图生成输出
- android - 如何在 Google Pixel XL 上打开视频库?
- oop - 如何在 Fortran 中使用多态数据类型作为另一种数据类型的属性
- android - 如何使用 Jetpack 的导航在片段中使用工具栏但不能在活动中使用工具栏
- javascript - ffmpeg 为 HTML MediaSource 流编码 mp4
- java - Gson“toJson”函数崩溃(Android Studio)
- node.js - 套接字 io 超时
- php - 传单错误“未捕获的错误:函数名称必须是字符串”
- google-sheets - 搜索一张工作表的列并从 CSV 中的单独工作表返回多个匹配项