Package: ecoindex_cli
Ecoindex-CliThis tool provides an easy way to analyze websites withEcoindexfrom your local computer using multi-threading. You have the ability to:Make the analysis on multiple pagesDefine multiple screen resolutionMake a recursive analysis from a given websiteThis CLI is built on top ofecoindex-scraperwithTyperThe output is a CSV or JSON file with the results of the analysis.RequirementsDocker(optional)QuickstartThe simplest way to start with ecoindex-cli is to install docker and then create an alias in your .bashrc or .zshrc file:For MacOS and Windows :aliasecoindex-cli="docker run -it --rm -v /tmp/ecoindex-cli:/tmp/ecoindex-cli vvatelot/ecoindex-cli:latest ecoindex-cli"For Linux :aliasecoindex-cli="docker run -it --rm --add-host=host.docker.internal:host-gateway -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:ecoindex-cli--helpTo enable local testing we use the docker aliashost.docker.internalto access your machine localhost.
Currently,host.docker.internalis mapped to your IPv4 address. To facilitate local testing, ensure that your localhost is accessible via your IPv4 address (127.0.0.1).Use caseThe docker imagevvatelot/ecoindex-cliis available forlinux/amd64andlinux/arm64platforms and provides you an easy way to use this CLI on your environment.The one line command to use it is:ecoindex-clianalyze--urlhttps://www.ecoindex.fr--recursive--html-reportMake a simple analysisYou give just one web urlecoindex-clianalyze--urlhttps://www.ecoindex.frResult📁️Urlsrecordedinfile`/tmp/ecoindex-cli/input/www.ecoindex.fr.csv`Thereare1url(s),doyouwanttoprocess?[Y/n]:1urlsfor1windowsizewith8maximumworkers100%━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━1/1•0:00:10•0:00:00
┏━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━┓
┃Totalanalysis┃Success┃Failed┃
┡━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━┩
│1│1│0│
└────────────────┴─────────┴────────┘
🙌️File/tmp/ecoindex-cli/output/www.ecoindex.fr/2023-14-04_140013/results.csvwritten!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-sizeand--chrome-versionYou can add multiple urls to analyze with the option--url. For example:ecoindex-clianalyze--urlhttps://www.ecoindex.fr--urlhttps://www.ecoindex.fr/a-propos/Provide urls from a fileYou 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-clianalyze--urls-fileinput/ecoindex.csvResult📁️Urlsrecordedinfile`/tmp/ecoindex-cli/input/www.ecoindex.fr.csv`Thereare2url(s),doyouwanttoprocess?[Y/n]:2urlsfor1windowsizewith8maximumworkers100%━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━2/2•0:00:14•0:00:00
┏━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━┓
┃Totalanalysis┃Success┃Failed┃
┡━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━┩
│2│2│0│
└────────────────┴─────────┴────────┘
🙌️File/tmp/ecoindex-cli/output/www.ecoindex.fr.csv/2023-14-04_140853/results.csvwritten!Make a website analysis based on the website's sitemapThe cli allows for the analysis of a designated website using its sitemap. By entering the sitemap URL, the app identifies and analyzes all pages within the website. ⚠️ This can process for a very long time!Use it at your own risks!ecoindex-clianalyze--sitemaphttps://www.ecoindex.fr/sitemap.xmlResultYouareabouttoreadurlsfromawebsitesitemap.Thiscantakealongtime.Areyousuretowanttoproceed?[Y/n]:⏲️Crawlingsitemapurlhttps://www.ecoindex.fr/sitemap.xml->Waitaminute!2024-02-2018:38:16[scrapy.utils.log]INFO:Scrapy2.11.1started(bot:scrapybot)2024-02-2018:38:16[scrapy.utils.log]INFO:Versions:lxml5.1.0.0,libxml22.12.3,cssselect1.2.0,parsel1.8.1,w3lib2.1.2,Twisted23.10.0,Python3.12.2(main,Feb132024,08:34:52)[GCC12.2.0],pyOpenSSL24.0.0(OpenSSL3.2.130Jan2024),cryptography42.0.3,PlatformLinux-6.4.16-linuxkit-aarch64-with-glibc2.36
📁️Urlsrecordedinfile`/tmp/ecoindex-cli/input/www.ecoindex.fr.csv`Thereare22url(s),doyouwanttoprocess?[Y/n]:y22urlsfor1windowsizewith10maximumworkers100%━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━22/22•0:00:20•0:00:00
┏━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━┓
┃Totalanalysis┃Success┃Failed┃
┡━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━┩
│22│22│0│
└────────────────┴─────────┴────────┘
🙌️File/tmp/ecoindex-cli/output/www.ecoindex.fr/2024-02-20_183842/results.csvwritten!Note: When utilizing the sitemap method with the --recursive flag, please be aware that the recursive flag will not take effect.Make a recursive analysisYou 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-clianalyze--urlhttps://www.ecoindex.fr--recursiveResultYouareabouttoperformarecursivewebsitescraping.Thiscantakealongtime.Areyousuretowanttoproceed?[Y/n]:⏲️Crawlingrooturlhttps://www.ecoindex.fr->Waitaminute!
-2023-04-1414:09:38[scrapy.utils.log]INFO:Scrapy2.8.0started(bot:scrapybot)2023-04-1414:09:38[scrapy.utils.log]INFO:Versions:lxml4.9.2.0,libxml22.9.14,cssselect1.2.0,parsel1.7.0,w3lib2.1.1,Twisted22.10.0,Python3.11.3(main,Apr52023,14:15:06)[GCC9.4.0],pyOpenSSL23.0.0(OpenSSL3.0.87Feb2023),cryptography39.0.2,PlatformLinux-5.15.0-67-generic-x86_64-with-glibc2.312023-04-1414:09:38[scrapy.crawler]INFO:Overriddensettings:{'LOG_ENABLED':False}📁️Urlsrecordedinfile`/tmp/ecoindex-cli/input/www.ecoindex.fr.csv`Thereare7url(s),doyouwanttoprocess?[Y/n]:7urlsfor1windowsizewith8maximumworkers100%━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━7/7•0:00:25•0:00:00
┏━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━┓
┃Totalanalysis┃Success┃Failed┃
┡━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━┩
│7│7│0│
└────────────────┴─────────┴────────┘
🙌️File/tmp/ecoindex-cli/output/www.ecoindex.fr/2023-14-04_141011/results.csvwritten!Generate a html reportYou can generate a html report easily at the end of the analysis. You just have to add the option--html-report.ecoindex-clianalyze--urlhttps://www.ecoindex.fr--recursive--html-reportResultYouareabouttoperformarecursivewebsitescraping.Thiscantakealongtime.Areyousuretowanttoproceed?[Y/n]:⏲️Crawlingrooturlhttps://www.ecoindex.fr->Waitaminute!
-2023-04-1414:16:13[scrapy.utils.log]INFO:Scrapy2.8.0started(bot:scrapybot)2023-04-1414:16:13[scrapy.utils.log]INFO:Versions:lxml4.9.2.0,libxml22.9.14,cssselect1.2.0,parsel1.7.0,w3lib2.1.1,Twisted22.10.0,Python3.11.3(main,Apr52023,14:15:06)[GCC9.4.0],pyOpenSSL23.0.0(OpenSSL3.0.87Feb2023),cryptography39.0.2,PlatformLinux-5.15.0-67-generic-x86_64-with-glibc2.312023-04-1414:16:13[scrapy.crawler]INFO:Overriddensettings:{'LOG_ENABLED':False}📁️Urlsrecordedinfile`/tmp/ecoindex-cli/input/www.ecoindex.fr.csv`Thereare7url(s),doyouwanttoprocess?[Y/n]:7urlsfor1windowsizewith8maximumworkers100%━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━7/7•0:00:28•0:00:00
┏━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━┓
┃Totalanalysis┃Success┃Failed┃
┡━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━┩
│7│7│0│
└────────────────┴─────────┴────────┘
🙌️File/tmp/ecoindex-cli/output/www.ecoindex.fr/2023-14-04_141645/results.csvwritten!
🦄️Amazing!Areporthasbeengeneratedto/tmp/ecoindex-cli/output/www.ecoindex.fr/2023-14-04_141645/index.htmlWhen generating a html report, the results are written in a CSV file and you can not specify the result file location. So options--export-formatand--output-fileare ignored.Here is a sample result:Other featuresSet the output fileYou can define the csv output fileecoindex-clianalyze--urlhttps://www.ecoindex.fr--output-file~/ecoindex-results/ecoindex.csvExport to JSON fileBy default, the results are exported to a CSV file. But, you can specify to export the results to a JSON file.ecoindex-clianalyze--urlhttps://www.ecoindex.fr--export-formatjsonChange wait before / after scrollBy 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-scrolland--wait-after-scrollto fit your needs.ecoindex-clianalyze--urlhttps://www.ecoindex.fr--wait-before-scroll1--wait-after-scroll1Using multi-threadingYou 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:ecoindex-clianalyze--urlhttps://www.ecoindex.fr--urlhttps://www.greenit.fr/--max-workers10By default, the number of maximum workers is set to CPU count.Disable console interactionYou 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.ecoindex-clianalyze--urlhttps://www.ecoindex.fr--recursive--no-interactionOnly generate a report from existing result fileIf 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-clireport"/tmp/ecoindex-cli/output/www.ecoindex.fr/2021-05-06_191355/results.csv""www.synchrone.fr"Result🦄️Amazing!Areporthasbeengeneratedto/tmp/ecoindex-cli/output/www.ecoindex.fr/2021-05-06_191355/index.htmlResults exampleThe result of the analysis is a CSV or JSON file which can be easily used for further analysis:CSV examplewidth,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,websiteJSON example[{"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 descriptionwidthis the screen width used for the page analysis (in pixels)heightis the screen height used for the page analysis (in pixels)urlis the analysed page urlsizeis the size of the page and of the downloaded elements of the page in KBnodesis the number of the DOM elements in the pagerequestsis the number of external requests made by the pagegradeis the corresponding ecoindex grade of the page (from A to G)scoreis the corresponding ecoindex score of the page (0 to 100)gesis the equivalent of greenhouse gases emission (ingCO2e) of the pagewateris the equivalent water consumption (incl) of the pagedateis the datetime of the page analysispage_typeis the type of the page, based ton theopengraph type tagDevelopmentRequirementsPython 3.10+PoetryTaskInstallationAt first, you need to install dependencies:poetryinstall
poetryrunplaywrightinstallchromium--with-depsUsagepoetryrunecoindex-cli--help
poetryrunecoindex-clianalyze--help
poetryrunecoindex-clireport--helpTestingWe use Pytest to run unit tests for this project. The test suite are in thetestsfolder. Just execute :poetryrunpytest--cov-reportterm-missing:skip-covered--cov=.--cov-config=.coveragerctestsThis runs pytest and also generate acoverage report(terminal and html)