Open Sustainable Technology

A curated list of open technology projects to sustain a stable climate, energy supply, biodiversity and natural resources.

Browse accepted projects | Review proposed projects | Propose new project | Open Issues

Ecoindex_cli

This tool provides an easy way to analyze websites with Ecoindex from your local computer using multi-threading.
https://github.com/cnumr/ecoindex_cli

ecoindex greenit python typer

Last synced: about 10 hours ago
JSON representation

Repository metadata

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 with multiple screen resolution. You can also make a recursive analysis from a given website.

README

        

:warning: This project is being replaced by [ecoindex_python_fullstack](https://github.com/cnumr/ecoindex_python_fullstack) and will be archived soon. Please refer to the new project for any contribution or issue. :warning:

# Ecoindex-Cli

[![Quality check](https://github.com/cnumr/ecoindex_cli/workflows/Quality%20checks/badge.svg)](https://github.com/cnumr/ecoindex_cli/actions/workflows/quality.yml)
[![PyPI version](https://badge.fury.io/py/ecoindex-cli.svg)](https://badge.fury.io/py/ecoindex-cli)

This tool provides an easy way to analyze websites with [Ecoindex](https://www.ecoindex.fr) from your local computer using multi-threading. 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](https://pypi.org/project/ecoindex/) with [Typer](https://typer.tiangolo.com/)

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

## Requirements

- [Docker](https://docs.docker.com/get-docker/)

## Quickstart

The simplest way to start with ecoindex-cli is to install docker and then create an alias in your .bashrc or .zshrc file:

```bash
alias ecoindex-cli="docker run -it --rm -v /tmp/ecoindex-cli:/tmp/ecoindex-cli vvatelot/ecoindex-cli:latest ecoindex-cli"
```

Then you can use the cli as if it was installed on your computer:

```bash
ecoindex-cli --help
```

## Use case

The docker image [vvatelot/ecoindex-cli](https://hub.docker.com/r/vvatelot/ecoindex-cli) is available for `linux/amd64` and `linux/arm64` platforms and provides you an easy way to use this CLI on your environment.

The one line command to use it is:

```bash
ecoindex-cli analyze --url https://www.ecoindex.fr --recursive --html-report
```

### Make a simple analysis

You give just one web url

```bash
ecoindex-cli analyze --url https://www.ecoindex.fr
```

Result

```bash
πŸ“οΈ Urls recorded in file `/tmp/ecoindex-cli/input/www.ecoindex.fr.csv`
There are 1 url(s), do you want to process? [Y/n]:
1 urls for 1 window size with 8 maximum workers
100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1/1 β€’ 0:00:10 β€’ 0:00:00
┏━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━┓
┃ Total analysis ┃ Success ┃ Failed ┃
┑━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━┩
β”‚ 1 β”‚ 1 β”‚ 0 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜
πŸ™ŒοΈ File /tmp/ecoindex-cli/output/www.ecoindex.fr/2023-14-04_140013/results.csv written !
```

> This makes an analysis with a screen resolution of 1920x1080px by default and with the last known version of chromedriver. You can set those settings with options: `--window-size` and `--chrome-version`
> You can add multiple urls to analyze with the option `--url`. For example:

```bash
ecoindex-cli analyze --url https://www.ecoindex.fr --url https://www.ecoindex.fr/a-propos/
```

### 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.

```bash
ecoindex-cli analyze --urls-file input/ecoindex.csv
```

Result

```bash
πŸ“οΈ Urls recorded in file `/tmp/ecoindex-cli/input/www.ecoindex.fr.csv`
There are 2 url(s), do you want to process? [Y/n]:
2 urls for 1 window size with 8 maximum workers
100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2/2 β€’ 0:00:14 β€’ 0:00:00
┏━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━┓
┃ Total analysis ┃ Success ┃ Failed ┃
┑━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━┩
β”‚ 2 β”‚ 2 β”‚ 0 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜
πŸ™ŒοΈ File /tmp/ecoindex-cli/output/www.ecoindex.fr.csv/2023-14-04_140853/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!**

```bash
ecoindex-cli analyze --url https://www.ecoindex.fr --recursive
```

Result

```bash
You are about to perform a recursive website scraping. This can take a long time. Are you sure to want to proceed? [Y/n]:
⏲️ Crawling root url https://www.ecoindex.fr -> Wait a minute!
-2023-04-14 14:09:38 [scrapy.utils.log] INFO: Scrapy 2.8.0 started (bot: scrapybot)
2023-04-14 14:09:38 [scrapy.utils.log] INFO: Versions: lxml 4.9.2.0, libxml2 2.9.14, cssselect 1.2.0, parsel 1.7.0, w3lib 2.1.1, Twisted 22.10.0, Python 3.11.3 (main, Apr 5 2023, 14:15:06) [GCC 9.4.0], pyOpenSSL 23.0.0 (OpenSSL 3.0.8 7 Feb 2023), cryptography 39.0.2, Platform Linux-5.15.0-67-generic-x86_64-with-glibc2.31
2023-04-14 14:09:38 [scrapy.crawler] INFO: Overridden settings:
{'LOG_ENABLED': False}
πŸ“οΈ Urls recorded in file `/tmp/ecoindex-cli/input/www.ecoindex.fr.csv`
There are 7 url(s), do you want to process? [Y/n]:
7 urls for 1 window size with 8 maximum workers
100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 7/7 β€’ 0:00:25 β€’ 0:00:00
┏━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━┓
┃ Total analysis ┃ Success ┃ Failed ┃
┑━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━┩
β”‚ 7 β”‚ 7 β”‚ 0 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜
πŸ™ŒοΈ File /tmp/ecoindex-cli/output/www.ecoindex.fr/2023-14-04_141011/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`.

```bash
ecoindex-cli analyze --url https://www.ecoindex.fr --recursive --html-report
```

Result

```bash
You are about to perform a recursive website scraping. This can take a long time. Are you sure to want to proceed? [Y/n]:
⏲️ Crawling root url https://www.ecoindex.fr -> Wait a minute!
-2023-04-14 14:16:13 [scrapy.utils.log] INFO: Scrapy 2.8.0 started (bot: scrapybot)
2023-04-14 14:16:13 [scrapy.utils.log] INFO: Versions: lxml 4.9.2.0, libxml2 2.9.14, cssselect 1.2.0, parsel 1.7.0, w3lib 2.1.1, Twisted 22.10.0, Python 3.11.3 (main, Apr 5 2023, 14:15:06) [GCC 9.4.0], pyOpenSSL 23.0.0 (OpenSSL 3.0.8 7 Feb 2023), cryptography 39.0.2, Platform Linux-5.15.0-67-generic-x86_64-with-glibc2.31
2023-04-14 14:16:13 [scrapy.crawler] INFO: Overridden settings:
{'LOG_ENABLED': False}
πŸ“οΈ Urls recorded in file `/tmp/ecoindex-cli/input/www.ecoindex.fr.csv`
There are 7 url(s), do you want to process? [Y/n]:
7 urls for 1 window size with 8 maximum workers
100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 7/7 β€’ 0:00:28 β€’ 0:00:00
┏━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━┓
┃ Total analysis ┃ Success ┃ Failed ┃
┑━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━┩
β”‚ 7 β”‚ 7 β”‚ 0 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜
πŸ™ŒοΈ File /tmp/ecoindex-cli/output/www.ecoindex.fr/2023-14-04_141645/results.csv written !
πŸ¦„οΈ Amazing! A report has been generated to /tmp/ecoindex-cli/output/www.ecoindex.fr/2023-14-04_141645/index.html
```

> When generating a html report, the results are written in a CSV file and you can not specify the result file location. So options `--export-format` and `--output-file` are ignored.

Here is a sample result:
![Sample report](doc/report.png)

### Other features

#### Set the output file

You can define the csv output file

```bash
ecoindex-cli analyze --url https://www.ecoindex.fr --output-file ~/ecoindex-results/ecoindex.csv
```

#### Export to JSON file

By default, the results are exported to a CSV file. But, you can specify to export the results to a JSON file.

```bash
ecoindex-cli analyze --url https://www.ecoindex.fr --export-format json
```

### Change wait before / after scroll

By default, the scenario waits 3 seconds before and after scrolling to bottom of the page so that the analysis results are conform to the Ecoindex main API methodology.

You can change this value with the option `--wait-before-scroll` and `--wait-after-scroll` to fit your needs.

```bash
ecoindex-cli analyze --url https://www.ecoindex.fr --wait-before-scroll 1 --wait-after-scroll 1
```

### Using a specific Chrome version

You can use a specific Chrome version to make the analysis. This is useful if you use an old chrome version. You just have to provide the main Chrome version number.

```bash
ecoindex-cli analyze --url https://www.ecoindex.fr --chrome-version 107
```

Or if you do not know the Chrome version number, you can use the one line command

```bash
ecoindex-cli analyze --url https://www.ecoindex.fr --chrome-version (google-chrome --version | grep --only -P '(?<=\\s)\\d{3}')
```

### Using multi-threading

You can use multi-threading to speed up the analysis when you have a lot of websites to analyze. In this case, you can define the maximum number of workers to use:

```bash
ecoindex-cli analyze --url https://www.ecoindex.fr --url https://www.greenit.fr/ --max-workers 10
```

> By default, the number of maximum workers is set to CPU count.

### Disable console interaction

You can disable confirmations, and force the app to answer yes to all of them. It can be useful if you need to start the app from another script, or if you have no time to wait it to finish.

```bash
ecoindex-cli analyze --url https://www.ecoindex.fr --recursive --no-interaction
```

### 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 :

```bash
ecoindex-cli report "/tmp/ecoindex-cli/output/www.ecoindex.fr/2021-05-06_191355/results.csv" "www.synchrone.fr"
```

Result

```bash
πŸ¦„οΈ Amazing! A report has been generated to /tmp/ecoindex-cli/output/www.ecoindex.fr/2021-05-06_191355/index.html
```

## Results example

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

### CSV example

```csv
width,height,url,size,nodes,requests,grade,score,ges,water,date,page_type
1920,1080,https://www.ecoindex.fr,521.54,45,68,B,75.0,1.5,2.25,2022-05-03 22:28:49.280479,
1920,1080,https://www.greenit.fr,1374.641,666,167,E,32.0,2.36,3.54,2022-05-03 22:28:51.176216,website
```

### JSON example

```json
[
{
"width": 1920,
"height": 1080,
"url": "https://www.ecoindex.fr",
"size": 521.54,
"nodes": 45,
"requests": 68,
"grade": "B",
"score": 75.0,
"ges": 1.5,
"water": 2.25,
"date": "2022-05-03 22:25:01.016749",
"page_type": null
},
{
"width": 1920,
"height": 1080,
"url": "https://www.greenit.fr",
"size": 1163.386,
"nodes": 666,
"requests": 148,
"grade": "E",
"score": 34.0,
"ges": 2.32,
"water": 3.48,
"date": "2022-05-03 22:25:04.516676",
"page_type": "website"
}
]
```

### Fields description

- `width` is the screen width used for the page analysis (in pixels)
- `height` is the screen height used for the page analysis (in pixels)
- `url` is the analysed page url
- `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
- `water`is the equivalent water consumption (in `cl`) of the page
- `date` is the datetime of the page analysis
- `page_type` is the type of the page, based ton the [opengraph type tag](https://ogp.me/#types)

## Development

### Requirements

- Python 3.10+
- [Poetry](https://python-poetry.org/)
- [Chrome](https://www.google.com/chrome/) (or [Chromium](https://www.chromium.org/))
- [ChromeDriver](https://chromedriver.chromium.org/)

### Installation

At first, you need to install dependencies:

```bash
git clone
cd ecoindex-cli
poetry install
```

You also need to install Google Chrome or Chromium and the corresponding [ChromeDriver](https://chromedriver.chromium.org/) for your OS.

You have to download the chrome driver and put it in the project path. You can also use the `--chromedriver-path` option to specify the path to the chrome driver.

### Usage

```bash
poetry run ecoindex-cli --help
poetry run ecoindex-cli analyze --help
poetry run ecoindex-cli report --help
```

### Testing

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

```bash
poetry run pytest --cov-report term-missing:skip-covered --cov=. --cov-config=.coveragerc tests
```

> This runs pytest and also generate a [coverage report](https://pytest-cov.readthedocs.io/en/latest/) (terminal and html)

## Disclaimer

The LCA values used by [ecoindex_cli](https://github.com/cnumr/ecoindex_cli) to evaluate environmental impacts are not under free license - Β©FrΓ©dΓ©ric Bordage
Please also refer to the mentions provided in the code files for specifics on the IP regime.

## [License](LICENSE)

## [Contributing](CONTRIBUTING.md)

## [Code of conduct](CODE_OF_CONDUCT.md)


Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: 27 days ago

Total Commits: 183
Total Committers: 6
Avg Commits per committer: 30.5
Development Distribution Score (DDS): 0.59

Commits in past year: 41
Committers in past year: 3
Avg Commits per committer in past year: 13.667
Development Distribution Score (DDS) in past year: 0.146

Name Email Commits
Vincent Vatelot v****t@i****e 75
dependabot[bot] 4****] 70
Vincent Vatelot v****t@g****m 34
mikefromlig m****a@i****r 2
David DE CARVALHO d****5@g****m 1
Vincent Vatelot v****t@i****r 1

Committer domains:


Issue and Pull Request metadata

Last synced: about 11 hours ago

Total issues: 27
Total pull requests: 147
Average time to close issues: 3 months
Average time to close pull requests: 14 days
Total issue authors: 17
Total pull request authors: 4
Average comments per issue: 4.26
Average comments per pull request: 0.64
Merged pull request: 57
Bot issues: 0
Bot pull requests: 98

Past year issues: 15
Past year pull requests: 99
Past year average time to close issues: 2 months
Past year average time to close pull requests: 17 days
Past year issue authors: 12
Past year pull request authors: 4
Past year average comments per issue: 4.53
Past year average comments per pull request: 0.71
Past year merged pull request: 32
Past year bot issues: 0
Past year bot pull requests: 70

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/cnumr/ecoindex_cli

Top Issue Authors

  • vvatelot (4)
  • benel (3)
  • hrenaud (3)
  • edouard-lopez (2)
  • revolunet (2)
  • Lucas-C (2)
  • ZoeThivet (1)
  • YanouHDecath (1)
  • xadag-yogarik (1)
  • simonvdfr (1)
  • PierreRustOrange (1)
  • KevinDias91 (1)
  • j75 (1)
  • guillaumew (1)
  • fredlux55 (1)

Top Pull Request Authors

  • dependabot[bot] (98)
  • vvatelot (47)
  • dedece35 (1)
  • guillaumew (1)

Top Issue Labels

  • bug (15)
  • Stale (8)
  • enhancement (7)
  • Mac (3)
  • good first issue (1)
  • feature (1)
  • chore (1)
  • Docker (1)
  • keep open (1)

Top Pull Request Labels

  • dependencies (98)
  • python (75)
  • Stale (25)
  • chore (23)
  • github_actions (16)
  • fix (6)
  • feature (5)
  • refactor (2)
  • documentation (1)

Package metadata

pypi.org: ecoindex_cli

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

  • Homepage: http://www.ecoindex.fr
  • Documentation: https://ecoindex_cli.readthedocs.io/
  • Licenses: Creative Commons BY-NC-ND
  • Latest release: 2.26.0 (published about 11 hours ago)
  • Last Synced: 2024-02-28T18:17:58.255Z (about 11 hours ago)
  • Versions: 48
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 2,095 Last month
  • Rankings:
    • Dependent packages count: 9.927%
    • Downloads: 15.14%
    • Average: 30.195%
    • Dependent repos count: 65.518%
  • Maintainers (2)

Dependencies

poetry.lock pypi
  • atomicwrites 1.4.0 develop
  • black 22.6.0 develop
  • coverage 6.4.2 develop
  • iniconfig 1.1.1 develop
  • mypy-extensions 0.4.3 develop
  • pathspec 0.9.0 develop
  • platformdirs 2.5.2 develop
  • pluggy 1.0.0 develop
  • py 1.11.0 develop
  • pytest 7.1.2 develop
  • pytest-cov 3.0.0 develop
  • async-generator 1.10
  • attrs 21.4.0
  • automat 20.2.0
  • certifi 2022.6.15
  • cffi 1.15.0
  • charset-normalizer 2.1.0
  • click 8.1.3
  • click-spinner 0.1.10
  • colorama 0.4.5
  • constantly 15.1.0
  • cryptography 37.0.3
  • cssselect 1.1.0
  • cycler 0.11.0
  • ecoindex 4.1.0
  • ecoindex-scraper 1.6.1
  • filelock 3.7.1
  • fonttools 4.33.3
  • greenlet 1.1.2
  • h11 0.13.0
  • hyperlink 21.0.0
  • idna 3.3
  • incremental 21.3.0
  • itemadapter 0.6.0
  • itemloaders 1.0.4
  • jinja2 3.1.2
  • jmespath 1.0.1
  • kiwisolver 1.4.3
  • lxml 4.9.1
  • markupsafe 2.1.1
  • matplotlib 3.5.2
  • numpy 1.23.0
  • outcome 1.2.0
  • packaging 21.3
  • pandas 1.4.3
  • parsel 1.6.0
  • pillow 9.1.1
  • protego 0.2.1
  • pyasn1 0.4.8
  • pyasn1-modules 0.2.8
  • pycparser 2.21
  • pydantic 1.9.1
  • pydispatcher 2.0.5
  • pyopenssl 22.0.0
  • pyparsing 3.0.9
  • pypydispatcher 2.1.2
  • pysocks 1.7.1
  • python-dateutil 2.8.2
  • pytz 2022.1
  • pyyaml 6.0
  • queuelib 1.6.2
  • requests 2.28.1
  • requests-file 1.5.1
  • scrapy 2.6.2
  • selenium 4.3.0
  • service-identity 21.1.0
  • setuptools-scm 7.0.3
  • six 1.16.0
  • sniffio 1.2.0
  • sortedcontainers 2.4.0
  • sqlalchemy 1.4.39
  • sqlalchemy2-stubs 0.0.2a24
  • sqlmodel 0.0.6
  • tldextract 3.3.0
  • tomli 2.0.1
  • trio 0.21.0
  • trio-websocket 0.9.2
  • twisted 22.4.0
  • twisted-iocpsupport 1.0.2
  • typer 0.6.1
  • typing-extensions 4.2.0
  • undetected-chromedriver 3.1.5.post4
  • urllib3 1.26.9
  • w3lib 1.22.0
  • websockets 10.3
  • wsproto 1.1.0
  • zope.interface 5.4.0
pyproject.toml pypi
  • black ^22.3 develop
  • pytest ^7.1 develop
  • pytest-cov ^3.0.0 develop
  • Jinja2 ^3.0.1
  • PyYAML ^6.0
  • Scrapy ^2.5.0
  • click-spinner ^0.1.10
  • ecoindex-scraper ^1.6.0
  • matplotlib ^3.4.3
  • pandas ^1.3.3
  • pydantic ^1.8.2
  • python ^3.8
  • typer >=0.3.2,<0.7.0

Score: 13.268186911158082