Skip to content

EgbieAndersonUku1/price_alerter_app

Repository files navigation

Better Code Hub

Using the Better Code Hub at https://bettercodehub.com I ran my entire price_alerter_app repository against the clean code standards to measure whether my coding standards where good or bad. Below is the coding compliance result it gave me.

BCH compliance

I lost one mark in Automate test because I did not write unit tests (I have the unit tests on my computer but have not upload it to this repository) and the other was in keep unit interface small because three of class constructor methods contained more than four parameters.

Price Alert application

Started on 14th April 2018 completed

Project 98 percent complete

Technologies Used

  1. Python3.6
  2. MongoEngine
  3. MailGun API
  4. Flask
  5. CSS
  6. HTML

What is price Alerter?

Price Alerter is an online web based application that allows users to track the prices of any online item. The app allows the user to create a given store along with the price of the item they want to track.

The app will then monitor the price of the item and if the prices changes the user would be alerted of the new price by email.

The site comes with three predefined stores Ebay, Amazon and Game that allows the user create an item which the user can then add an alert to.

Using Price Alerter

To use Price Alerter you need to use MailGun API. The MailGun API allows user to be able to send and receive emails.

Registering with MailGun to send emails

To be able to use the send_email method in the Mailgun class file you must first register your details at www.mailgun.com. Don't worry registration is free and no card details is needed.

Once registration is completed and necessary verification are done you be given a sandbox account which allows the user to send 300 emails a day and 10,000 emails a month. The only downside is the sandbox account allows you to only send emails to your registered account which is good for development purposes.

To send emails to other people's account you need to create/register a domain

Log into your account using your newly created details, you will be greeted by a dashboard

  1. click on the 'Domains' tab
  2. Click the link inside 'Domain name'. The link should start with a sandbox

You will then be a greeted with the follow pages details: These details are secret and should not be shown to anyone

  1. State: Active
  2. IP Address: IP Address
  3. SMTP Hostname: smtp.mailgun.org
  4. Default SMTP Login: postmaster@sandbox.mailgun.org
  5. API Base URL https://api.mailgun.net/v3/.mailgun.org/messages
  6. Default Password: < Random string for password>
  7. Key: key < random string>

Entering your details in the Mailgun_constant.py file

Open the Mailgun_constant file. Inside there are three constants. These are 'URL', 'API_KEY' and 'FROM'

**Enter your details into the following mailgun_constant.py file constants **

  1. Enter your 'API BASE URL' in the URL constant below makes sure to end the URL with a slash '/messages or it will not work
  2. Enter your 'Key' in the API_KEY constant below
  3. Enter your 'Default SMTP Login' in FROM constant below
  4. Hit save and then you good to go

Running Price-alerter on your computer

  1. Open a terminal create a folder and call it whatever you want
  2. Inside that folder we are going to create a virtual environment
  3. Type virtualenv --python=python3.6 venv and hit enter. This will create your virtuale environment
  4. To activate the virtual environment on Linux enter the command source venv/bin/activate
  5. To activate the virtual environment on Window enter the command \venv\Scripts\activate
  6. Now the run the command pip3.6 install -r requirement.txt. This download all the programs needed to run the program. Make sure that your are running it inside a virtual machine this allows you to easily delete the app by deleting the virtual machine
  7. Enter your administrator e-mail in src/config.py this is the email that you used to register with the MAILGUN website.
  8. Define your Mailgun API details on src/models/alerts/constants.py
  9. In the settings file for the UPLOAD FOLDER replace the path with the pathway to your img directory. e.g /home/some pathway/static/img. This is where your images would be stored
  10. change your secret key if you wish
  11. Run the command mongod to activate the mongo server. In some case you might need to run it with admin priviledges
  12. Run the Flask server by running python run.py runserver

Running the application

  1. Open a browser and enter the url http://127.0.0.1:5000/register/

register

  1. Register your details. Unfortuntately because you are using Mailgun the free tier the email you use to register with the app must be the one you used to register with MailGun. This is where the verification email will be sent to.

  2. Verify your email

  3. Login to the app

login

  1. Click on my stores

my_stores

  1. You will be created with a button telling you that you have not created any stores yet

no_stores

  1. Enter the details for your new store. For knowledge on how to create the span and store query see the about about page. In this example we will be creating the store ebay and all items created will belong to the ebay store

ebay

  1. After hitting create store you will be greeted with this page

new_store

  1. Click on view store

view_store

  1. Click on create item.

new_item

  1. Click on the create button

success

Note the item url must be a prefix of the store. For example if the store prefix is https://www.ebay.com then item url must be https://www.ebay.com/some-random-string. If the item Url prefix does not match the store's url then error will be thrown. If the item already exists then an error message will also be thrown

If the item's url does not match the store's prefix an error would also be thrown

does_not_match

Adding an item to the db that will result in an error if the item already exists

item_already_exists

  1. To view an item *Click on my store *Go to store you wish to view the item and click *Inside you will see all items belong to the store *Click on view item

view_item

blue_ray_player

blue_ray_player_2

Notice the item has no alert in the image number 12

To add an alert to an item hit the alert button. This enables an alert to be set to an item. You will then be notified by email whenever your item's prices reaches that limit.

Let add £40 to our alert. We shall now be alerted should our item price hit £40

new_alert

Now if click active alerts page we see

active_alert

Notice that our alerts message at the top of the page is now active

active_alert_image

We can also disable

disabled_alert

or delete the alert

delete_alerted

Many to many relationship implemented into the database

The database's uses a many to many relationship. This simple means that all items created belong to the store and all alerts created belong to the item. For instance if an alert was deleted for a particular item, the item itself would still exists. But if the store was deleted all items and alerts that are created within the store will also be deleted as well.

shop_store

The store has been deleted and with that all items and alerts from database. From the GUI we can only access the item through the store and the alert through the item. With the store deleted there is no GUI handler (button) to access the item and no GUI handler (button) to access the alerts.

Because we had only one store created the page displays you have not create a store message but if we had a series of stores, then the page will display all stores that have not been deleted and the user would able to access any item and alerts created.

no_stores

About

Allows the user to track their online prices for any item

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published