Skip to content

Mindik/project1

Repository files navigation

Project 1

Web Programming with Python and JavaScript

Project completed in CS50W course. Used Goodreads API and Heroku PostgreSQL database.

The project was implemented in PyCharm 2020.1.2 (Professional Edition). Applied technology Flask, Jinja2, JavaScript, HTML5, CSS3 (SASS).

The task can be viewed at the link - Project 1: Books.

The task sounds like this:

«In this project, you’ll build a book review website. Users will be able to register for your website and
then log in using their username and password. Once they log in, they will be able to search for books,
leave reviews for individual books, and see the reviews made by other people. You’ll also use the a third-party
API by Goodreads, another book review website, to pull in ratings from a broader audience. Finally,
users will be able to query for book details and book reviews programmatically via your website’s API.»

Data for connecting to the database is specified in the application.py file. The 10,000 rows Heroku provided for free
was not enough for me, so I temporarily bought the next database plan (10,000,000 rows), which costs $ 9 per month.
After checking my project, I will not pay for the database, so it may not work. In addition, Heroku periodically
changes connection data when using its first tariffs, so the database may stop working before I cancel my subscription.

Project structure

Core files

  1. requirements.txt

    The file contains a list of libraries used to run the application.

     pip3 install -r requirements.txt 
    
  2. application.py

    The main file that initializes the application. This file links the application, consisting of different files, into a single whole. Here are the keys to the Heroku database Goodreads URI APIs. To launch the application, use the commands:

     set FLASK_APP=application.py
    
     flask run
    
  3. config.py

    Project configuration file. Contains the basic settings for the application. Flask_mail settings and so on.

  4. views.py

    File of the main application paths. The basic logic for the application is described here.
    Which implements certain functions when navigating to a specific URL.

  5. forms.py

    Contains helper objects. Here I tried to use the basics of OOP. Uses FlaskForm. Most database queries are described here.

  6. helpers.py

    This is a file from CS50 Finance. Authorization Check Function. I added the function of checking the extension of the downloaded files to this file and sending a message to the email address.

  7. static

    The directory where the application files are located (image, CSS, JS)

    • script.js

      The main script written in JavaScript. I tried to leave detailed comments, but my knowledge of English is low :(.

      My experience in JS is minimal. I was looking for information on Google to implement certain functions.

    • style.scss

      SASS file containing CSS markup for all pages of the application.

    • img

      A directory with 5,000 book covers downloaded! :) (minimum file size)

    • ava

      Directory of user images.

  8. templates

    The directory where the HTML markup templates are located. The main layout.html template.
    The rest are related to him, thanks to Jinja2

  9. Database schema

    schema DB

Additional files

  1. secretKey.py

    Secret key generation (more)

  2. start.txt

    An additional file for debugging, so as not to write commands every time.

  3. import.py

    Program for reading books.csv and subsequent import into Heroku Database

    To start use the command:

    Set the environment variable DATABASE_URL to be the URI of your database, which you should be able to see from the credentials page on Heroku.

     python import.py
    
  4. parc_img_text.py

    Additional file for downloading book covers and text book descriptions.

    Images will be saved in the specified directory. Text and file name will be added to the database.

    Set the environment variable DATABASE_URL to be the URI of your database, which you should be able to see from the credentials page on Heroku.

     python parc_img_text.py
    

App appearance

Sign up

Sign up

To use the functions of the site you need to register, indicating the name, surname, email address and password.
Using Bootstrap 4 validation.

Validation

Additionally, the function of checking the coincidence of passwords and viewing the entered passwords is implemented.

Password check and view

After entering the data and submitting the form, the server will process the request,
enter the new data into the database and send an email with a link to confirm the mailbox.

Send email

Activate

If the specified mailbox address is already in use, you will see a message about this.

Error

ATTENTION! The mailbox name is not case sensitive (MyEMail@exaMPLe.com == myemail@example.com), unlike the rest of the fields.

If the user tries to enter the site without confirming the mailbox, the application will not allow this, and the sign in form will offer to re-send the letter.

Resend

On the page for re-sending the letter, you need to specify your mailing address. If you specify a mailbox that
is not in the database or it has already been verified, you will receive an error message.

Resend form

Otherwise, you will receive a letter to the specified mailbox, in which there will be a link with a GET request.

Resend mail

GET

After clicking on the link from the letter, you will automatically activate your account.

Reg fine

Sign in

After activation, you can log in with your account.

Sign in

Forgot your password? Do not despair! It can be reset! How? Again through your mailing address.

Forgot password

You need to go to the forgot password link and specify the address of your mailbox. If such an address exists, then
a letter will be sent to you, and on the screen you will see a message

Ok reset

In case of an error, the message will be different!

Error reset password

After clicking on the link from the letter, you will see a form that will allow you to change your password. When you submit a login form, if you provide an incorrect username or password, you will receive a message about this.
Otherwise, you will be taken to the main page of the site.

Sign in form

Index page

Index page

  1. Personal profile

    Pressing

    Botton profile.

    A form of personal information will open before you, which no one sees, except you. The page has your photo, the number of your ratings and reviews. You also have the right to upload a new photo, no larger than 5 MB.

    View profile

    I was not able to test error 413 on either the local or AWS EB server. The @ app.errorhandler (413) handler refuses to process it more details.

    In the forms below you can change your password or email. In case of input errors, you will also receive error messages.

    Others form error

    Others form error

    Others form error

    If you succeeded in successfully changing the password or email, then you will receive a success message.

    Others form ok

    Others form ok

    The password can be changed by confirming your account by entering the old password. Changing the mailbox address will require confirmation through the new address.

    Change email

  2. Information Button

    By clicking on the icon

    Info

    You will see a window with general statistics showing the number of books, reviews and registered users.

    Info

  3. The main function is the search! By clicking on the icon

    Search botton form

    You will see a search box

    Window search

    You can enter isbn. Title, author book. Both fully and partially. Register does not matter at all.

    Isbn full

    Isbn min

    Author

    Title min

    Title full

    The search form responds to Enter (Numpad Enter), but you can use the search button. By the way, do not worry about the number of books in the search! On the screen you will see a maximum of
    20 books on one page and 20 pages. Pages can be switched by ArrayLeft / ArrayRight.

    Page number

    Page number

    The text and image for the books were taken from the goodreads website, using the small Python code I wrote (parc_img_text.py).
    I attached this code to the project. I hope that goodreads are not against the use of their materials for educational (and only!) Purposes.

    If the book already has grades, then the stars will be colored proportionally! Check it out!

    Rating books

  4. Log out By clicking on the button on the home page

    Log out

    you will end your session and sign out.

A page of a book.

If you want to leave a review about the book, then you can go to its page!
If you have not left a review, then you will see a button that will open the feedback form for you.

IMPORTANT! All fields must be filled!

Book page

Book page

If you have already left your rating, then this form will not be! I did not give the opportunity to delete my reviews that I left earlier, since “the first word is more expensive than the second” ©

Book page

You can leave a response that will be added to others without refreshing the page 
nd the overall rating data will also be updated immediately !!! Thanks JSON!

By the way, the text of the books as a result of the search and on the pages of the book is different (in most cases).

Pay attention to the rating of books according to goodreads (API). They are updated every time the page is refreshed.

Book page

API

By the way, we now also have our own API! It is easy to access, go to / api / isbn. Specify the number of the book you selected instead of isbn.

API

By completing a similar request, you will get such a result.

API ok

If you specify an invalid isbn, you will receive an error in the form of JSON and a 404 code for the browser.

API error

Any 404 errors will lead to a redirect to the main page.

Adaptive layout

Adaptive

Adaptive

Adaptive

Adaptive

Adaptive

Adaptive

Adaptive

Adaptive

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published