Eco Design is a toolkit for analyzing the ecodesign of websites, incorporating:
- 🚀 Google PageSpeed Insights
- 🌍 Ecoindex
- 🔍 Network Request Analysis
Utilizes the Google PageSpeed Insights API to evaluate website performance. API Documentation
Employs Playwright to scrape websites and calculate their Ecoindex score. Adapted from ecoindex_python.
Leverages Playwright to examine network requests made by the website.
from app.core.insight.google_insight import MobileInsight, DesktopInsight
url = "https://www.alextraveylan.fr"
# Mobile Insight
mobile_insight = MobileInsight(url)
print(mobile_insight.get_result())
# Output: performance=85 accessibility=100 best_practices=96 seo=100 ...
# Desktop Insight
desktop_insight = DesktopInsight(url)
print(desktop_insight.get_result())
# Output: performance=99 accessibility=100 best_practices=100 seo=100 ...
from app.core.eco_index.scraper import EcoindexScraper
url = "https://www.alextraveylan.fr"
eco_index = asyncio.run(EcoindexScraper(url=url).get_page_analysis())
print(eco_index)
# Output: size=296.448 nodes=386 requests=30 grade=<Grade.B: 'B'> score=75.0 ges=1.5 water=2.25 ...
from app.core.inspect_network.count_requests import InspectNetwork
url = "https://www.alextraveylan.fr"
inspect = InspectNetwork(url=url)
print(inspect.get_result())
# Output: total=32 js=19 css=1
- Python 3.10+
- pip
- Clone the repository
- Set up a virtual environment:
python -m venv env
- Install dependencies:
pip install -r dev_requirements.txt
- Install Playwright browsers:
playwright install
python app/main.py
from app.usecase.excel_completion.actions import create_excel_from_template
from app.usecase.excel_completion.files_infos import (
TEMPLATE_PATH,
get_output_path,
)
output_path = get_output_path()
urls: List[str] = [
"https://www.francetravail.fr/accueil",
"https://www.alextraveylan.fr/fr",
"https://it-wars.com/",
]
create_excel_from_template(TEMPLATE_PATH, output_path, urls)
# A file will be create here : app/usecase/excel_completion/data/output
- Commande
# Général (strategy : desktop or mobile)
python .\app\entrypoint\cli\main.py insight [URL] [strategy]
# Exemple
python .\app\entrypoint\cli\main.py insight https://www.alextraveylan.fr/fr desktop
- Output
[INFO|setup_logging|L39] 2024-10-07T09:36:48+0200: Logger initialized.
{
'performance': 99,
'accessibility': 100,
'best_practices': 100,
'seo': 100,
'first_contentful_paint': 218,
'largest_contentful_paint': 401,
'total_blocking_time': 87,
'cumulative_layout_shift': 0.0,
'speed_index': 1091
}
- Commande
# Général
python .\app\entrypoint\cli\main.py eco-design [URL]
# Exemple
python .\app\entrypoint\cli\main.py eco-design https://www.alextraveylan.fr/fr
- Output
[INFO|setup_logging|L39] 2024-10-07T09:37:18+0200: Logger initialized.
{
'url': 'https://www.alextraveylan.fr/fr',
'size': 297.026,
'nodes': 386,
'requests': 29,
'grade': <Grade.B: 'B'>,
'score': 76.0,
'ges': 1.48,
'water': 2.22,
'date': datetime.datetime(2024, 10, 7, 9, 37, 21, 605695),
'page_type': None
}
- Commande
# Général
python .\app\entrypoint\cli\main.py network [URL]
# Exemple
python .\app\entrypoint\cli\main.py network https://www.alextraveylan.fr/fr
- Output
[INFO|setup_logging|L39] 2024-10-07T09:37:18+0200: Logger initialized.
{'total': 31, 'js': 19, 'css': 1}
- Commande
# Général
python .\app\entrypoint\cli\main.py complete-excel [URLS...]
# Exemple
python .\app\entrypoint\cli\main.py complete-excel https://www.alextraveylan.fr/fr https://it-wars.com
- Output
Should open the created excel file.
Execute tests:
pytest
This project is configured for Visual Studio Code with Python extension settings for formatting and linting. Configuration files are located in the .vscode
directory.
Build the Docker image:
docker build -t eco-design .
Run the container:
docker run -p 80:80 eco-design
GitHub Actions workflow is set up for CI, running tests and security checks on push and pull request events to the main branch.
Logging is configured using Python's built-in logging module. Configuration file: app/adapter/logger/config_log.json
.
Create the package:
python setup.py sdist bdist_wheel
Install the package:
pip install dist/ecodesign-0.1-py3-none-any.whl
Note: Replace 0.1
with the current version number.
Contributions are welcome! Please submit a pull request or create an issue to discuss proposed changes.
This project is licensed under the MIT License.