The live link can be found here.
This project was created as part of the Full Stack Software Development course offered by Code Institute.
- Python Virtual Assistant Task
The purpose of this project is to put into practice the knowledge about the Python language acquired during the course, such as:
- The use of the Python Language.
- The use of the Python Virtual Environment.
- The use of the Python in the Terminal.
- Creating of variables and assign a value to them.
- Data Structures.
- Tuples.
- Lists.
- Dictionaries.
- Sets.
- Decision Structures.
- If/Else statements.
- Repetition Structures.
- For loop.
- While loop.
- Functions.
- The use of the Python Libraries.
- and many others.
Python Virtual Assistant Task is a Python terminal application, which runs on a mock terminal on Heroku.
The goal of this Python application is to create a virtual assistant that can be used to perform tasks from the command line. Basically, the virtual assistant will be able to perform tasks like:
- Add a new task to the list of tasks.
- List all the tasks in the list.
- Remove a task from the list of tasks.
- Restore a task from the list of removed tasks.
We know that nowadays, the vast majority of web applications have a chatbot to help the user in their daily tasks. As a result, the idea of developing a virtual task assistant is quite pertinent.Through this application, the user will be able to count on the help of a virtual agent that will help him according to what is requested. If the user wants to add a new task, the agent will do it. And so on.
As a site owner, I would like to provide users an easy and solid backend application.
To create the flowchart, I have used the LucidChart tool.
-
User Stories This site is created based on the following user’s expectations in mind.
-
As a first time user I would like to:
- Have a clear information on what the application is about and what it does
- Have an easy understanding about how the application works
- Have clear feedback for my action taken within the application
-
As a site creator we would like :
- To provide a safe and friendly application that anyone can use.
-
-
Features
- The application should be user-friendly on all browsers and devices.
- Intuitive and user-friendly site that any people can gain and share experiences.
- The purpose of the application should be clear immediately.
-
User Story:
- As a first time visitor to the webapp, I would like to immediately understand its purpose.
Acceptance Criteria:
- Once the program is run, a welcome message is displayed, making it clear to the user the purpose of the application.
Implementation:
A welcome message is displayed to the user. E.g. "Welcome to the Python Virtual Task Assistant...". Therefore, the user can immediately understand that the purpose of the application is a Virtual Task Assistant.
Result: User Story accomplished.
User Stories:
- I would like to be able to choose between adding a task, seeing tasks that have already been added, deleting a task that has already been completed and restore tasks that have been deleted, if I wish to.
- I would like the application to be friendly and easy to understand and use.
Acceptance Criteria:
- User can choose to add a task to a list of new tasks.
- User can choose to view the list of tasks.
- User can choose to delete a task that has already been completed.
- User can choose to restore a task that has already been deleted.
Implementation:
Upon the program runs, the application will display a menu with the following options:
1- Add a task 2- View tasks 3- Delete a task 4- Restore a task
The user can choose to add a task, view the list of tasks, delete a task, or restore a task, as their preference.
**Result:** User Story accomplished.
This is a list of Irish names that I have used in the application. Each time that the program runs, a random name will be chosen from this list.
- My target audience is those people who wish to use an application to perform tasks.
- Be able to add a new task, If I wish to.
- Be able to view all the tasks I have added so far.
- Be able to delete a task that has already been completed.
- Be able to restore a task that has already been deleted by mistake.
- Receive by email a LiveChat transcript of the conversation with the virtual assistant.
- As I develop, I want all the features to be working as expected.
- I want the user to have the best experience throughout the application.
- I want to showcase my skills in Python Programming Language.
- During the deployment of the application, I noticed that the program was not running properly. The email was not being sent to the user, as expected. After reading Heroku's documentation, I could see that in addition to creating an environment variable that could improve compatibility with various Python libraries (
PORT=8000
), I had to create a new environment variable that communicates with the email service (in this case, the SMTP server from Gmail -PORT_GMAIL=465
). After that, the program was running properly and the email was being sent to the user.
- When checking the code from
send_email.py
through the PEP8 online checker, an error was displayed, as shown in the image below.
with smtplib.SMTP_SSL(host=host, port=port, context=context) as server:
with smtplib.SMTP_SSL(host, port, context=context) as server:
Error fixed after removing host
and port
parameters from the SMTP_SSL function.
- The same error happens in the function
functions.py
, as shown in the image below.
chatbot_message(
"Sorry. I didn't understand what you said.\nCan you please say it again?"
)
Fixed bug when splitting string into two lines.
chatbot_message(
"Sorry. I didn't understand what you said."
"\nCan you please say it again?"
)
- Python: Used to develop all application logic. - python.org/
- sys: Used to access the command line arguments.
- os: Used to clean the output of the command line.
- random: Used to choose a random name from a list of agents names, each time the program is run.
- datetime: Used to get the current date and time.
- time.sleep: Used to pause the program for a certain amount of time.
- ssl: Used to access the SMTP server from Gmail.
- smtplib: Used to send emails from the application.
- email.mime.base: Used to create the email message.
- email.mime.text: Used to create plain text emails.
- email.mime.multipart: Used to create emails with attachments.
- environs: Used to access the environment variables.
- pyisemail: Used to validate the email address.
-
Gitpod: An online IDE also used for creating & saving code that runs in a browser, it does not have to be installed on your PC - https://www.gitpod.io/
-
Git: A version control system for tracking changes in source code during software development - https://git-scm.com/
-
Github: A company that provides hosting for software development version control using Git. It is a subsidiary of Microsoft - https://github.com/
-
VSCode: A free and open-source text editor for software development - https://code.visualstudio.com/
-
Heroku: A cloud-based platform for deploying and managing web applications - https://www.heroku.com/
-
Gmail: A web-based email service that allows users to send and receive email - https://www.gmail.com/
-
If the user enter a wrong input in the beginning of the program (e.g. entering an empty string or a number instead of a string), the program should not crash.
-
If the user enters a wrong input in the menu options (e.g. entering a number that is not one of the options), the program should not crash.
-
If the user chooses to view the list of tasks and there is no task to be displayed, the program should not crash.
-
If the user tries to delete a task whose index does not exist, the program should not crash.
- It should work the same way for the restore_task() function.
-
When the user opts out of the conversation, the agent will ask if he wants to receive a copy of the conversation by email. The user is expected to enter [Y] for Yes or [N] for No. If the user enters any other input than these, the program should not crash.
-
If the user enters a wrong input in the email address field, the program should not crash.
The function validate_email_address() is used to validate the email address. It receives as parameter the email address and check whether the domain used in the email is a valid domain and whether or not it has a valid MX record. It returns True if the email address is valid and False if it is not.
** Please note that a valid response here is not a guarantee that the email exists, merely that is can exist. **
-
If for some reason the program cannot connect to the SMTP server, the program should not crash.
-
Application tested using PEP8 Online Check PEP8 Online Check.
-
All code is written in Python 3.10.0
By forking the GitHub Repository we make a copy of the original repository on our GitHub account to view and/or make changes without affecting the original repository by using the following steps...
-
Log in to GitHub and locate the GitHub Repository
-
At the top of the Repository (not top of page) just above the "Settings" Button on the menu, locate the "Fork" Button.
-
You should now have a copy of the original repository in your GitHub account.
-
Run the index.html file in your local browser.
To set up heroku you must:
- If your requirements.txt file has not changed you can skip this step. Otherwise, in your terminal type 'pip freeze > requirements.txt' then save and push the changes.
- Go to Heroku.com and sign in or create a free account.
- From the heroku dashboard click the 'Create new app' button.
- Name the app something unique and choose what region you are in then click 'Create app'.
- Go to the settings tab and find the Config Vars section. Click 'Reveal Config Vars'.
- For this project, you required to add a environment variable to connect to SMTP server from GMAIL. In the field KEY, enter PORT_GMAIL in all capitals, then for VALUE enter 465. (Note that you must differentiate between PORT and PORT_GMAIL. Otherwise, your deployment may fail) Then click 'Add'.
- In the field for KEY enter PORT in all capitals, then in the field for VALUE enter 8000. Then click 'Add'.
- Scroll down to the Buildpacks section and click 'Add buildpack'.
- Click Python then save changes.
- Add another buildpack by clicking 'Add buildpack' and this time click Nodejs then save changes.
- Make sure that Python appears above Nodejs in the buildpack section. If it does not you can click and drag them to change the order.
- Then head over to the deploy section by clicking deploy from the nav bar at the top of the page.
- From the 'Deployment method' section select GitHub and click 'Connect to GitHub'.
- Enter the repository name as it is in GitHub and click 'search'.
- Click the 'connect' button next to the repository to link it to heroku.
- To deploy, scroll down and click the 'Deploy Branch' button.
- Heroku will notify you that the app was successfully deployed with a button to view the app.
- If you want to rebuild your app automatically you can also select the 'Enable Automatic Deploys' button which will then rebuild the app every time you push any changes.
-
The code to send email is credited to Real Python
I would like to take the opportunity to thank:
- My family, friends and colleagues for their advice, support and help with testing.
- To my mentor Felipe Alarcon for his feedback, advice, support and, above all, for his patience.
- All Code Institute Tutors and Community on Slack for the peer reviews and advice.
Made with ❤️ by Emidio Valereto 👋🏽 Get in touch!