-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcarboncli.py
44 lines (37 loc) · 1.19 KB
/
carboncli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import argparse
from carbon.calculator import CarbonCalculator
from carbon.services import LighthouseService, GreenWebService
def main():
""" """
parser = argparse.ArgumentParser(
description="Carbon Calculator - the tool calculates the carbon emissions (CO2) and green infos of any website"
)
parser.add_argument(
"-db",
"--greenweb",
type=str,
help="(Mandatory) - The path of the Green Web Foundation DB (SQL3Lite DB file)",
required=True,
)
parser.add_argument(
"-lh",
"--lighthouse",
type=str,
help="(Optional) - The path of the Lighthouse tool",
required=False,
)
parser.add_argument("website", type=str, help="The URL to analyze")
args = parser.parse_args()
try:
lighthouse = (
LighthouseService()
if not args.lighthouse
else LighthouseService(args.lighthouse)
)
greenweb = GreenWebService(args.greenweb)
website = args.website
carbon = CarbonCalculator(lighthouse=lighthouse, greenweb=greenweb)
carbon.footprint(website)
print(carbon.to_json())
except Exception as e:
print(e)