- A script that finds books on the Glasgow University library resource, takes reviews from Goodreads, and structures it in a database using REST API.
- The script is useful for those who want to quickly find top-rated or most popular books about a particular topic which are available to borrow from the library for free, instead of buying them.
- After the script is run, the JSON object is formed from the book results and sent to the server.
- Using sorting and/or filtering queries in a url, one can retrieve the books without empty reviews and sorted by number of reviews/best rating.
- Prerequisites: installed Python (version at least 3).
- Set up a local copy of the repository.
1.1. Open a terminal and navigate to the directory that you would like the Book finder to be stored in;
1.2. In the terminal, run to clone the repository into the current directory:git clone https://github.com/nikalinov/book_finder.git
- Navigate into the Book finder directory and create a virtual environment:
python3 -m venv <enter-venv-name-here>
- Activate the virtual environment:
(Linux/MacOS)
$ source <enter-venv-name-here>/bin/activate
or(Windows)<enter-venv-name-here>\Scripts\activate.bat
- Install the prerequisite modules/libraries from requirements.txt:
pip install -r requirements.txt
- It is needed to create a personal Django secret key. For that, navigate to the 'book_finder' directory
(which is in the original 'book_finder' project directory) and run:python3 secret_key_generator.py
- To turn on the Django server for sending data, run from the root directory:
python3 manage.py runserver
- Open another command line window to start a separate session, navigate into the 'script' directory of
the project and run the command:where the search query can be any phrase/word and the number must be at least 15.python3 find.py <enter-your-title-here> <enter-number-of-results-here>
One can omit the number and it will default to 15. For example,orpython3 find.py python 20
In case everything works correctly, the 2 messages will be displayed:python3 find.py java
Successfully found books! Successfully sent books to the server!
- The sent data is available via endpoints
http://127.0.0.1:8000/api/book/list/
(GET - retrieve book list,
POST - post a book record) andhttp://127.0.0.1:8000/api/book/<book_pk>
(GET - retrieve a book record).
For the book list, one can add a query variablessort
andfilter
, for example:
http://127.0.0.1:8000/api/book/list/?sort=rating&filter=true
- retrieves the book list sorted by highest
rating and with excluded zero-rating books (screenshot of the result).