-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
35 lines (32 loc) · 1.26 KB
/
main.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
import GTMetrix
import argparse
import logging
import time
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
if __name__ == '__main__':
parser = argparse.ArgumentParser(prog="GTMetrixRecommendation")
parser.add_argument(
"-u", "--url", type=str, required=True, help="The url of the page")
parser.add_argument(
"-o", "--output_file", help="the file to save the recommendations to", type=str, default="recommendations.txt")
parser.add_argument(
"-l", "--limit", help="The number of recommendations to display", type=int, default=6)
parser.add_argument(
"-v", "--verbose", help="Display debug message", action="store_true")
args = parser.parse_args()
email = "jose.colella@dynatrace.com"
apiToken = "43b7a445ee75fefe746e603d2bf783c2"
gtMetrix = GTMetrix.GTMetrixAPI(email, apiToken)
gtMetrix.requestTest(args.url)
logging.info("The test is being processed")
try:
gtMetrix.getTestResults()
time.sleep(16)
gtMetrix.getTestResults()
except KeyError:
# If the test is still in queue
time.sleep(16)
gtMetrix.getTestResults()
logging.info("Saving to file")
gtMetrix.savePageSpeedRecommendations(args.output_file, args.limit)