- Clone this repository onto your local machine. The root of this project will be the
movie-search-engine
directory.git clone https://github.com/kshitijavis/movie-search-engine.git movie-search-engine
- This app uses two datasets from the Movies Dataset on Kaggle. From Kaggle, download the
movies_metadata.csv
andkeywords.csv
files. Create adata
directory in the root of your project and move the two files into the new directory.
The following steps will create a MySQL user and database where movie data will be stored.
- Login to your MySQL server interactive prompt and crete a new database
CREATE DATABASE <database name>;
- Create a new user that Django can use to access your new database
CREATE USER <username>@'%' IDENTIFIED BY <password>;
- Grant privileges for the new user to the new database
GRANT ALL ON <database name>.* to <username>@'%';
- Flush privileges
FLUSH PRIVILEGES;
To connect Django to a MySQL database, you will need to add database information to a .env
file
Create a .env
in the root of your project and populate it like so
DATABASE_NAME=<database name>
DATABASE_USER=<database username>
DATABASE_PASSWORD=<database password>
DATABASE_HOST=<database host>
DATABASE_PORT=<port that database is running on>
Replace all fields wrapped in the angle brackets with your new database credentials.
- Make sure you have python3 downloaded.
- In your command line, navigate to the root of this project.
- Navigate to the backend directory
cd backend
- Setup tables in your database as specified in the Python Django configuration. This is done through Django migrations
python manage.py migrate
- Navigate to back to root directory and then to
scripts
directory.cd ..
- Run
store_data.py
script in thescripts
directory using Python. This will populate your new database tables with the data in your.csv
files.If you have trouble running this script, make sure your environment variables are setup correctly in yourpython scripts/store_data.py
.env
file and your data is correctly stored in adata
directory.
- In your command line, navigate to the root of this project
- Install python dependencies as specified in
requirements.txt
. You may want to install dependencies in a virtual environment.pip install -r requirements.txt
- Navigate to the frontend directory. Then install node dependencies.
cd frontend npm install
- Run the backend Django server
python mange.py runserver
- Navigate to the frontend directory
cd .. cd frontend
- Run the client server
npm start
- The movie search engine should now be running locally on
localhost:3000
The /movies/<id>
endpoint on the React App gives detailed information about a given movie. The app also uses Google Custom Search Engine (GCSE) to find and display a cover image of the movie. To set up image-rendering, follow these steps.
- Visit GCSE API. Scroll down and click the blue Get a Key button. This will prompt you to sign in using Google credentials.
- Once signed in, you should see a prompt to Enable Custom Search API. Click the drop down and press + Create a new Project. Type in "Movie Search Engine" and hit next.
- You should receive an API Key. This needs to be added as an environment variable. Open up
.env
at the root of this project and add the following:
GOOGLE_API_KEY=<your API key>
- Visit your GCSE Control Panel and press the Add button. Enter "images.google.com" under Sites to search. Click Create
- On the next page, hit the Control Panel button. Then look for Search engine ID. This ID will also need to be added to our environment variables. Add this to
.env
GOOGLE_ENGINE_ID=<search engine id>
- Back on the Control Panel page in your browser, scroll down to Image search switch the toggle to On. Similarly, scroll down to Search the entire web and switch that toggle to On.
Now, the first image that GCSE finds for a given movie will be displayed on the app.
Running the project test suite requires a test database. Create the database by running the following MySQL commands.
GRANT ALL ON test_<database name>.* to <username>@'%';
FLUSH PRIVILEGES;
Where is the name of the database created while installing this app. Note that the test database name prepends test_
to the application database.
The following error sometimes occurres on MacOS systems when connecting to MySQL
ImportError: dlopen(.../.venv/lib/python3.8/site-packages/MySQLdb/_mysql.cpython-38-darwin.so, 2): Library not loaded: @rpath/libmysqlclient.21.dylib
...
Reason: image not found
If this error occurs, add the following to your bash/zsh configuration file
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/