· 7 years ago · Jan 04, 2019, 04:38 AM
1import sqlite3
2 from sqlite3 import Error
3 def create_connection(db_file):
4""" create a database connection to the SQLite database
5 specified by db_file
6:param db_file: database file
7:return: Connection object or None
8"""
9try:
10 conn = sqlite3.connect(db_file)
11 return conn
12except Error as e:
13 print(e)
14
15return None
16def create_table(conn, create_table_sql):
17""" create a table from the create_table_sql statement
18:param conn: Connection object
19:param create_table_sql: a CREATE TABLE statement
20:return:
21
22"""
23try:
24 c = conn.cursor()
25 c.execute(create_table_sql)
26except Error as e:
27 print(e)
28
29def main():
30database = "/Users/Erudition/Desktop/imdb_database/sqldatabase.db"
31
32sql_create_tile_akas = """ CREATE TABLE IF NOT EXISTS title (
33 titleid text PRIMARY KEY,
34 ordering integer NOT NULL,
35 title text,
36 region text,
37 language text NOT NULL,
38 types text NOT NULL,
39 attributes text NOT NULL,
40 isOriginalTitle integer NOT NULL
41
42 ); """
43
44conn = create_connection(database)
45if conn is not None:
46 # create projects table
47 create_table(conn, sql_create_tile_akas)
48
49else:
50 print("Error! cannot create the database connection.")
51
52if __name__ == '__main__':
53 main()
54
55imdbpy2sql.py -d /Users/Erudition/Desktop/imdb_database/aka-titles.list/
56 -u sqlite:///sqldatabase.db'''
57
58WARNING The file will be skipped, and the contained
59WARNING information will NOT be stored in the database.
60WARNING Complete error: [Errno 20] Not a directory:
61'/Users/Erudition/Desktop/imdb_database/aka-titles.list/complete-
62cast.list.gz'
63WARNING WARNING WARNING
64WARNING unable to read the "/Users/Erudition/Desktop/imdb_database/aka-
65titles.list/complete-crew.list.gz" file.
66WARNING The file will be skipped, and the contained
67WARNING information will NOT be stored in the database.
68WARNING Complete error: [Errno 20] Not a directory:
69'/Users/Erudition/Desktop/imdb_database/aka-titles.list/complete-
70crew.list.gz'