Skip to main content

`ecoindex-cli` is a CLI tool that let you make ecoindex tests on given pages

Project description

Ecoindex-Cli

Quality check PyPI version

This tool provides an easy way to analyze websites with Ecoindex from your local computer. You have the ability to:

  • Make the analysis on multiple pages
  • Define multiple screen resolution
  • Make a recursive analysis from a given website

This CLI is built on top of ecoindex-python with Typer

The output is always a CSV file with the results of the analysis.

Current limitation: This does not work well with SPA.

Requirements

  • Python ^3.8
  • pip
  • Google Chrome installed on your computer

Setup

 pip install --user -U ecoindex-cli

Use case

The cli gets 2 commands: analyze and report which can be used separately:

 ecoindex-cli --help                                Usage: ecoindex-cli [OPTIONS] COMMAND [ARGS]...

  Ecoindex cli to make analysis of webpages

Options:
  --install-completion [bash|zsh|fish|powershell|pwsh]
                                  Install completion for the specified shell.
  --show-completion [bash|zsh|fish|powershell|pwsh]
                                  Show completion for the specified shell, to
                                  copy it or customize the installation.

  --help                          Show this message and exit.

Commands:
  analyze  Make an ecoindex analysis of given webpages or website.
  report   If you already performed an ecoindex analysis and have your...

Make a simple analysis

You give just one web url

 ecoindex-cli analyze --url http://www.ecoindex.fr
There are 1 url(s), do you want to process? [Y/n]:
1 urls for 1 window size
Processing  [####################################]  100%
🙌️ File /tmp/ecoindex-cli/output/www.ecoindex.fr/2021-04-20 16:44:33.468755/results.csv written !

This makes an analysis with a screen resolution of 1920x1080px by default

Set the output file

You can define the csv output file

 ecoindex-cli analyze --url http://www.ecoindex.fr --output-file ~/ecoindex-results/ecoindex.csv
📁️ Urls recorded in file `input/www.ecoindex.fr.csv`
There are 1 url(s), do you want to process? [Y/n]: 
1 urls for 1 window size
Processing  [####################################]  100%
🙌️ File /home/vvatelot/ecoindex-results/ecoindex.csv written !

Multiple url analysis

 ecoindex-cli analyze --url http://www.ecoindex.fr --url https://www.greenit.fr/
There are 2 url(s), do you want to process? [Y/n]:
2 urls for 1 window size
Processing  [####################################]  100%
🙌️ File /tmp/ecoindex-cli/output/www.ecoindex.fr/2021-04-20 16:45:24.458052/results.csv written !

Provide urls from a file

You can use a file with given urls that you want to analyze: One url per line. This is helpful if you want to play the same scenario recurrently.

 ecoindex-cli analyze --urls-file input/ecoindex.csv
There are 2 url(s), do you want to process? [Y/n]:
2 urls for 1 window size
Processing  [####################################]  100%
🙌️ File /tmp/ecoindex-cli/output/www.ecoindex.fr/2021-04-20 16:45:24.458052/results.csv written !

Make a recursive analysis

You can make a recursive analysis of a given webiste. This means that the app will try to find out all the pages into your website and launch an analysis on all those web pages. ⚠️ This can process for a very long time! Use it at your own risks!

 ecoindex-cli analyze --url http://www.ecoindex.fr --recursive
⏲️ Crawling root url http://www.ecoindex.fr -> Wait a minute !
📁️ Urls recorded in file `/tmp/ecoindex-cli/input/www.ecoindex.fr.csv`
There are 3 url(s), do you want to process? [Y/n]:
3 urls for 1 window size
Processing  [####################################]  100%
🙌️ File /tmp/ecoindex-cli/output/www.ecoindex.fr/2021-04-20 16:47:29.072472/results.csv written !

Set other screen resolutions

You can provide other screen resolutions. By default, the screen resolution is 1920x1080px but you can provide other resolution for example if you want to test ecoindex for mobile.

 ecoindex-cli analyze --url http://www.ecoindex.fr --window-size 1920,1080 --window-size 386,540
There are 1 url(s), do you want to process? [Y/n]:
1 urls for 2 window size
Processing  [####################################]  100%
🙌️ File /tmp/ecoindex-cli/output/www.ecoindex.fr/2021-04-21 21:22:44.309077/results.csv written !

Generate a html report

You can generate a html report easily at the end of the analysis. You just have to add the option --html-report.

 ecoindex-cli analyze --url http://www.ecoindex.fr --recursive --html-report
⏲️ Crawling root url http://www.ecoindex.fr -> Wait a minute !
📁️ Urls recorded in file `input/www.ecoindex.fr.csv`
There are 3 url(s), do you want to process? [Y/n]:
3 urls for 1 window size
Processing  [####################################]  100%
🙌️ File output/www.ecoindex.fr/2021-04-21 21:21:27.629691/results.csv written !
🦄️ Amazing! A report has been generated to `/tmp/ecoindex-cli/output/www.ecoindex.fr/2021-04-21 21:21:27.629691/report.html`

Here is a sample result: Sample report

Only generate a report from existing result file

If you already performed an anlayzis and (for example), forgot to generate the html report, you do not need to re-run a full analyzis, you can simply request a report from your result file :

 ecoindex-cli report "/tmp/ecoindex-cli/output/www.ecoindex.fr/2021-05-06 19:13:55.735935/results.csv" "www.synchrone.fr"
🦄️ Amazing! A report has been generated to `/tmp/ecoindex-cli/output/www.ecoindex.fr/2021-05-06 19:13:55.735935/report.html`

Results example

The result of the analysis is a CSV file which can be easily used for further analysis:

size,nodes,requests,grade,score,ges,water,url,date,resolution,page_type
119.095,45,8,A,89,1.22,1.83,http://www.ecoindex.fr,2021-04-20 16:45:28.570179,"1920,1080",
769.252,730,94,D,41,2.18,3.27,https://www.greenit.fr/,2021-04-20 16:45:32.199242,"1920,1080",website

Where:

  • size is the size of the page and of the downloaded elements of the page in KB
  • nodes is the number of the DOM elements in the page
  • requests is the number of external requests made by the page
  • grade is the corresponding ecoindex grade of the page (from A to G)
  • score is the corresponding ecoindex score of the page (0 to 100)
  • ges is the equivalent of greenhouse gases emission (in gCO2e) of the page
  • wateris the equivalent water consumption (in cl) of the page
  • url is the analysed page url
  • date is the datetime of the page analysis
  • resolution is the screen resolution used for the page analysis (width,height)
  • page_type is the type of the page, based ton the opengraph type tag

Testing

In order to develop or test, you have to use Poetry, install the dependencies and execute a poetry shell:

poetry install
poetry shell

We use Pytest to run unit tests for this project. The test suite are in the tests folder. Just execute :

pytest --cov-report term-missing:skip-covered --cov=. --cov-config=.coveragerc tests

This runs pytest and also generate a coverage report (terminal and html)

Contributing

Code of conduct

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ecoindex-cli-2.0.1.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

ecoindex_cli-2.0.1-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file ecoindex-cli-2.0.1.tar.gz.

File metadata

  • Download URL: ecoindex-cli-2.0.1.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.8 CPython/3.8.2 Linux/5.8.0-1040-azure

File hashes

Hashes for ecoindex-cli-2.0.1.tar.gz
Algorithm Hash digest
SHA256 66a28e083f2b9076a250cc4d64bf60b008e9a867d11a3280db4f813297e67f81
MD5 6db7cc9606e3af0f3956fc20221c9fa4
BLAKE2b-256 33eb8981639c873f9ee6ceec55550d91970cdf3059851370b2707d514f92d589

See more details on using hashes here.

File details

Details for the file ecoindex_cli-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: ecoindex_cli-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 13.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.8 CPython/3.8.2 Linux/5.8.0-1040-azure

File hashes

Hashes for ecoindex_cli-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9686278c038f6f5db9bd858d88cd6fadf31132c55a25d30afef82fe2b172877f
MD5 00f552fb0b9a4fe9d05335864e19b8f7
BLAKE2b-256 ea4a9ee537536403860f3dca5438de909a3645f7cd9b4c5e211f24b57e878e36

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page