Five solutions for a simple Python project that finds and returns the titles of the 10 articles with the most comments from all available data, in descending order of the number of comments. If an article is missing the title field, then the story title will be used, if the story title is also missing, then such article will be discarded altogether.
Data from:
https://jsonmock.hackerrank.com/api/articles?page={page_number}
For the application to work correctly, it is important to follow the installation instructions.
Creating a Python virtual environment (venv) is important so that packages would only be installed for the project.
To create a Python virtual environment, go to the project folder in the terminal and run the following command:
python -m venv venv
Firstly, activate the venv.
Windows:
C:\project_dir> venv\Scripts\activate
Linux/Mac:
project_dir$ source venv/bin/activate
Next up install the necessary packages for the project:
$ pip install -r requirements.txt
To run the app in the Python Virtual Environment, run the following command:
flask run
Unit tests are used to check that the application is working as intended.
To run unit tests in the Python Virtual Environment, run the following command:
python -m unittest discover -s tests -p 'test_*.py'
There are 4 other solutions to this project, which do not have unit tests.
- complicated - uses pandas, possible to choose sorting, return, saved, replace values.
- semi_complicated - uses pandas
- using_page_reader_class - uses an object for reading pages
- using_page_reader_yield - uses yield to read pages
First 2 solutions were created before the main solution, are incomplete and could be improved on by taking inspiration from the main project.
PageReader object has unittests for it in the corresponding directory.
Run in the Python Virtual Environment by moving to the solution directory and running:
flask run