Dad Jokes is a console based application that accommodates individuals that are either interested in quick amusement of silly jokes or individuals that wants to share their silly jokes with other users. The user interface is text based and it is run from a text terminal or other types of command-in interfaces.
The application has two options at start that either lets the user read and rate a joke or submit a joke together with their name.
Target audience: All individuals that wants to read and rate a silly joke and all individuals that wants to submit a joke for future rating.
This project is the third of five milestone projects that needs to be completed in order for me to receive a diploma in Software Development from The Code Institute https://codeinstitute.net/
Required technologies for this project: Python
A live version of this project can be found at this url: https://dad-jokes-1.herokuapp.com/
This application is ment for:
- All individuals that wants amusements gotten by reading short silly jokes.
- All individuals that wants to share silly jokes and have the rated by other users.
I have divided the user stories for this application in to two different sections, User Reading and User Submitting. The scenarios do not differ much between Old users and New users.
- I want to read a silly joke.
- I want to rate a silly joke.
- I want to see who submitted silly jokes.
- I want to see the rating my submitted joke has. (Old user)
- I want to see if there is any more jokes since last time I used the application (Old user)
- I want to submit a silly joke.
- I want other users to read my silly joke.
- I want other users to rate my silly joke.
To get amused by silly jokes for a short period of time OR submit silly jokes.
Python application using libraries/API and deployed to a cloud-based platform.
Dad Jokes is a console based application. For that reason no work was put in to graphical design. Instead focus was put on creating a diagram of the entire application and use that as the base for the code. The diagram also include the Google Sheet used for data storage.
This is the initial diagram:
During the development process a few things were changed in the diagram. The main reason for this was that I had done a flaw in the design of the Google Sheet. I had placed the calculation formula for average score on jokes inside the sheet. I never got this to work properly so that column was eventually removed and the calculation is done in the application instead.
After the final alterations the final application diagram looks like this:
Dad Jokes consists of two features. The user chooses the option of feature from the start section of the application. The features are:
- Read and rate a joke
- Submit a joke
The user starts the read and rate option from the start section of the application. To read and rate the number 1 needs to be entered followed by the enter key.
After selection the user is presented with a random selected joke from the Google sheet. The user also sees the rating of the joke. The user is also asked to rate the joke by entering a number between 1 and 5.
When the rating has been entered the user is taken to the last section of this option. Here the user can choose to read and rate a new joke, restart the application or quit the application.
If j is selected the user will receive another joke and rate, if r is pressed the application starts over from the start selection screen and q will terminate the application.
The user starts the submit option from the start section of the application. To submit a joke the number 2 needs to be entered followed by the enter key.
After the selection the user is presented with an instruction to follow the steps and enter a name or a nickname. If the user enters a name shorter than two signs or longer than 10 signs they will be prompted to correct.
When name is entered the user is presented with instructions on how to write to make it easier for other users and prompted to enter their joke. If users tries to submit a very short joke or a joke longer than 300 signs they will be prompted to correct it. They user cannot submit empty jokes.
When the joke has been submitted the user is taken to the last section of this option. Here the user can choose to submit another joke, restart the application or quit the application.
If s is selected the user will restart the submit function, if r is pressed the application starts over from the start selection screen and q will terminate the application.
Future versions of this application will contain a graphical user interface and a capability for users to search and find the rating of their jokes.
Main languages
- Python
- HTML - Provided in the Code Institute template
- CSS - Provided in the Code Institute template
- JavaScript - Provided in the Code Institute template
Python libraries and api used
Jokes, submitted jokes, sumbmitter name and scores are fetched and stored in a Google Sheet using:
Testing has been conducted continuously during the development process. Manual testing has been conducted by the author and my mentor Martina Terlevic and fellow student Lauren-Nicole Popich. Read more about bugs during development and unfixed bugs for more information.
- Using Colorama library but my tests are not working. When I do a print syntax with the provided syntax to change the font color "Hello World" is not printing.
- Used the wrong syntax. Needed to add a "+" sign before the string
- Pure strings are using the selected colors but all prints from the worksheet are still white and I get a syntax error.
- Tried Termcolor library instead of Colorama library and it did the trick
- Get error messages when I try to access a specific row in the worksheet
- Used the wrong syntax for the library Gspread. Tried to install and import a different library but that was also problematic. Eventually I found the syntax for the Gspread library and it worked.
- Not able to add new rating with total rating
- The variables were strings, converted them to int's and it worked
- Not able to get a proper error message when rating not entered correctly
- Used an if/else statement to check and return if input is faulty
- The worksheet is not updating correctly. Can't figure out why.
- Went back to look at Love Sandwiches and created a function that updates the worksheet based on that project
- Can't figure out how to correctly copy the formula needed in the spreadsheet to get average rating.
- Will try to do the calculation inside Python instead. Update: Did overhaul all that had to do with average score. Removed the calculation of score from the spreadsheet and did the calculation in run.py instead
- When a joke is rated with a number containing a . or a , the application crashes.
- Added a try statement to check that the input is an integer
- On the end screens: If an integer or float value is entered the application crashes.
- Created a nested function inside the end function that validates the input and prevents crashing
- Application crashes if enter is pressed without a value in the end screens.
- Created a nested function inside the end function that validates the input and prevents crashing
- Users can submit joke and name with only white spaces.
- Added nested functions in both submit functions for joke and name that controlls lenght and check for white spaces.Found information on how to do it on https://www.geeksforgeeks.org/python-string-isspace-method/
- Average score is not calculated properly.
- The formula for average score was not correct. It contained wrong values. Corrected.
The code has also been tested by using PEP8 Online http://pep8online.com/.
Final testing warned about long lines. This has been corrected and the code passes without any issues.
Currently working to solve the bugs in this list. They will be moved to the Bugs during development section when they are solved.
- No known bugs at this point
The development environment used for this project was GitPod. To track the development stage and handle version control regular commits and pushes to GitHub has been conducted. The GitPod environment was created using a template provided by Code Institute.
The live version of the project is deployed using Heroku(https://heroku.com)
This is how this project was deployed using Heroku:
To prepare for deployment on Heroku a requirements.txt needs to be created in the same folder as the .py file in GitPod. This file needs to contain a list of all libraries the project needs to run as a Heroku App.
Then follow these steps:
- Login to Heroku (Create an account if necessary)
- Click on New in the Heroku dashboard and select ”Create new app”
- Write a name for the app and choose your region and click ”Create App”
- In the settings tab for the new application I created two Config vars.
- One is named CREDS and contains the credentials key for Google Drive API
- One is name PORT and has the value of 8000
- Two buildpack scripts were added: Python and Nodejs (in that order)
Heroku CLI was used to deploy the project. The following steps were taken in the terminal in GitPod
Deploying your app to heroku
- Login to heroku and enter your details.
- command: heroku login -i
- Get your app name from heroku.
- command: heroku apps
- Set the heroku remote. (Replace app_name with your actual app name)
- command: heroku git:remote -a app_name
- Add, commit and push to github
- command: git add . && git commit -m "Deploy to Heroku via CLI"
- Push to both github and heroku
- command: git push origin main
- command: git push heroku main
After those steps were taken the application was deployed at the following link: https://dad-jokes-1.herokuapp.com/
- All text content in the application is created by the author of the project.
- The initial 24 jokes in the Google Sheet are credited to Country Living and the submitter name for these jokes are set to CL
I have consulted numerous websites, individuals and slack channels to get support for the code. No code block is directly copied but some generates from information I gathered from other developers and sites:
- Google Sheets for Developers for information about exctracting information from a Google Sheet.
- Code Institute - Love Sandwiches for inspiration and understanding on how to develope the project.
- W3 Schools for understanding how to remove items from lists.
- W3 Schools for understanding variable conversion.
- Code Institute for all course material leading up to this project.
- Martina Terlevic My fantastic mentor at Code Institute, thank you for your support, feedback, bug testing and great sense of humor.
- Lauren-Nicole Popich Thank you for testing and contribution of ideas and dealing with my stress over this project.
Am I Responsive was used to create the image on top of this ReadMe