This project received an First Class equivalent grade. While there are minor issues, this was particularly one of my biggest accomplishments during my university journey and will continue to work on this project when free time allows.
- MongoDB - database used to store and retrieve unstructured data
- PyMongo - Python library to integrate database and server
- Server - Flask
- Browser - HTML,CSS,JS,BootStrap (If time allows, use React for scability)
- Cloud - Heroku
For further details, please refer to the Honours Project report found in page 27 onwards.
- Install MongoDB and MongoDBCompass - used to visualize data much more clearly
- Create a virtual environment in Python and activate it
python -m venv venv
- Ensure the Python dependencies from
requirements.txtare installed in the virtual environment, especially Flaskpip install -r requirements.txt
- Execute
setup_settings.pyon console - Go to
settings.iniand type in respective API and database settings- Database by default is called
db - Collections can either be named
bbcgoodfoodortasty.
- Database by default is called
- Run MongoDB in your local environment and connect it to localhost with port of 27017 (or MongoDBCloud database - lowest tier is free as of Feb 2023)
- Run
main.py- this deploys the Flask server only for local development and not production usage.
Folders named static and templates where static files and templates are respectively displayed.
web_scraping folder contains the Python files required to scrape the website.
honours_project_report folder contains the Honours Project report and images.
tests/ folder contains the automated test suite (see Running Tests below).
NOTE: Installation of Selenium and Google Chrome version is used for scraping data locally on the database. This is done separately from deploying onto Heroku. It should ideally be done on a personal local machine.
Configurable deployable websites include BBCGoodFood and Tasty. BBCGoodFood collections are supported such as https://www.bbcgoodfood.com/recipes/collection/february-recipes
Tasty website has more flexibility where base url is configured as https://tasty.co/search
The base_url of the website to scrape can be configured in the settings.ini file
- Simply run the respective Python website module. Go to cmd and go to the
web_scrapingfolder then typepython web_scrapping_module.py - Ensure the recipes are stored in the MongoDB collections
NOTE: Figure how to deploy settings config file securely
- Go to terminal
- Create and obtain the Heroku app name on heroku.com, after this then follow instructions given
- Remove
settings.inifrom.gitignore - Check in
requirements.txtfile to ensure Python dependencies are installed - Execute
git push heroku masteron your terminal - Add
settings.inito.gitignore
Heroku Configuration Setup Before Deploying: heroku config:set FOOD_RECIPE_DATABASE_USERNAME=your_username FOOD_RECIPE_DATABASE_PASSWORD=your_password FOOD_RECIPE_DATABASE_HOSTNAME=your_hostname -a
The project uses pytest-bdd (Gherkin/BDD style) with mongomock so no live MongoDB connection or environment variables are required.
pip install -r requirements.txt # Dependencies required for main app to run
pip install -r requirements-test.txtpython -m pytest tests/ -vpython -m pytest tests/ -v --cov=. --cov-report=term-missingtests/
├── conftest.py # App fixture (mongomock), seed data, shared step definitions
├── features/
│ ├── homepage.feature # Homepage load, featured recipes, cuisine browser
│ ├── search.feature # Filters: cuisine, dietary, time, sort, empty state
│ ├── recipe_detail.feature# Title, ingredients, directions, price, related recipes
│ └── time_converter.feature # Unit tests for the scraper time-string parser
└── step_defs/
├── test_homepage_steps.py
├── test_search_steps.py
├── test_recipe_detail_steps.py
└── test_time_converter_steps.py
CI runs automatically on every push and pull request to master via GitHub Actions (.github/workflows/ci.yml).
- Run the automated test suite and confirm all tests pass:
python -m pytest tests/ -v
- Conduct manual smoke tests in your local environment:
- Test search pagination: verify prev/next buttons work and results are consistent.
- Test pricing sort: search any term, sort by price, confirm ascending order.
- Test on mobile (Chrome DevTools) after each UI change to check responsive layout.
- Raise the PR to master from your feature branch
