daebowale / trivia

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Trivia App

this is a trivia game website that was created as part of my udacity course with some modifications from me,random questions are generated for you to answer based on the category you selected, it was developed using flask for backend and a react frontend.

the flask backend follows PEP8 guidelines for python.

Getting Started

you need to have python installed on your system with node and npm (a package manager for node) as the backend uses python flask framework and the frontend uses react.


Backend


  • install python if it's not installed from the official website

  • create a virtual environment in other to have an isolated system more info here

  • change directory to backend, install dependencies using pip

    pip install -r requirements.txt
    
  • due to Flask-Cors depreciation some codes have to be corrected from the flask module, open core.py in {path to your env}/python/version/lib/python/site-packages/flask_cors/core.py

    on line 322 and 342 change collections.Iterable to collections.abc.Iterable

  • install a relational database management system (rdbms), recommended rdbms is postgresql you can download and get more info here

  • create a database for the backend

    createdb trivia
    
  • you can choose to populated the trivia database with sample data provided or by yourself. to popluate the database change directory to ./backend and run

    psql trivia < trivia.psql
    
  • now to get the flask server running, if you intend to run it in a development environment, export the flask_env and flask_app variables first, change directory to backend

    for window cmd

    set FLASK_APP=flaskr
    set FLASK_ENV=development
    

    for window powershell

    $Env:FLASK_APP=flaskr
    $Env:FLASK_ENV=development
    

    for linux

    export FLASK_APP=flaskr
    export FLASK_ENV=development
    
  • you also need to set environment variables for the database user and the database password, the variables are DATABASE_USER and DATABASE_PASS respectively.

    for windows more info here

    for linux open your ~/.bashrc and add the following line of code to set the variables

        export DATABASE_USER="yourUsername" 
        export DATABASE_PASS="yourPassword"
    
  • finally run the server with

     flask run
    

Frontend


  • install nodejs from the official website here

  • install dependencies, change directory to frontend and run

    npm install //or
    npm i 
  • this app was created with react which provides a development server, change the script settings in package.json to your convenience if you are familiar with npm, run the development server with :

        npm run start
    
  • a production build can also be created using

        npm run build
    

Tests


tests are located in the backend directory in test_flaskr.py file, to run tests:

  • change directory to backend

  • create a database for the tests

    createdb trivia_test
    
  • populate the database with sample data

    psql trivia_test < trivia.psql
    
  • then run the script with python

    python test_flaskr.py
    

Api Reference

the documentation for the api is in the backend folder, link here

About

License:Other


Languages

Language:Python 53.3%Language:JavaScript 40.2%Language:CSS 5.4%Language:HTML 1.1%