I found a tutorial where you can input a movie in the terminal and it prints out on screen. It gets the information from IMDB. That part works fine. But then I decided I wanted to import that information to a SQLite database. When I run my program the table is made but it will not populate due to errors. One error is "no such column: id, so I deleted that just to see what would happen. It just goes to the next one and say "no such column: title.
Here is the code to print to screen that works:
I added the following for the SQLite database:
This is the traceback:
Here is the code to print to screen that works:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import imdb import sqlite3 hr = imdb.IMDb() movie_name = input ( "Enter the movie name : " ) movies = hr.search_movie( str (movie_name)) index = movies[ 0 ].getID() movie = hr.get_movie(index) title = movie[ 'title' ] year = movie[ 'year' ] cast = movie[ 'cast' ] rating = movie[ 'rating' ] plot = movie[ 'plot' ] list_of_cast = ',' .join( map ( str ,cast)) print ( "title" ,title) print ( "year of release: " ,year) print ( "full cast : " ,list_of_cast) print ( "rating: " ,rating) print ( "plot: " ,plot) print (movie.asXML()) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import sqlite3 from sqlite3 import Error conn = sqlite3.connect( 'movies.db' ) c = conn.cursor() print ( "Opened database successfully" ); conn.execute( '''CREATE TABLE IF NOT EXISTS data (ID INT PRIMARY KEY NOT NULL, title TEXT NOT NULL, year_of_release INT NOT NULL, full_cast TEXT NOT NULL, plot TEXT);''' ) print ( "Table created successfully" ); conn.execute("INSERT INTO data ( id , title, year_of_release, full_cast, plot) \ VALUES ( id , title, year_of_release, full_cast, plot)"); conn.commit() print ( "Records created successfully" ); conn.close() conn.close() |
Error:Traceback (most recent call last):
File "C:/Users/name/Documents/Python Projects/ImportIMDB/importimdb.py", line 38, in <module>
VALUES (id, title, year_of_release, full_cast, plot)");
sqlite3.OperationalError: no such column: id
Process finished with exit code 1
Thank you for any help that can be provided.