Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue in fetch function #1

Open
sabyasachiDs opened this issue Sep 1, 2021 · 3 comments
Open

Issue in fetch function #1

sabyasachiDs opened this issue Sep 1, 2021 · 3 comments

Comments

@sabyasachiDs
Copy link

Whenever i am calling fetch function its giving error:-

import json
import python_gtmetrix2

api_key = "e8ddc55d93eb0e8281b255ea236dcc4f" # your API key
account = python_gtmetrix2.Account(api_key) # init
test = account.start_test(url) # start test
test.fetch(wait_for_completion=True) # wait for it to finish
report = test.getreport() # get test result
print(json.dumps(report, indent=2)) # do something useful with it

Error:

TypeError: fetch() got an unexpected keyword argument 'wait_for_completion'

@sabyasachiDs sabyasachiDs changed the title Issue in fetch fuction Issue in fetch function Sep 1, 2021
@Lex-2008
Copy link
Owner

Lex-2008 commented Sep 1, 2021

Thanks! Fixed in it version 0.2.0 (also on main branch here on Github). Let me know if it works!

It happened because I was half-way renaming this argument from wait_for_complete to wait_for_completion - it had new name in docs, and old name in the code. I changed the code to have the new name everywhere. To add more 🤦 to this story, it's actually a positional argument, so you can as well just write test.fetch(True), and it will work perfectly fine (although it would be less clear what True actually means in this case, so trying to be helpful, I've added the argument name here). <insert facepalm emoji here>

@sabyasachiDs - let me know when you start writing some code which uses this library - I'll then make a release 1.0.0 and stop making incompatible changes (like, only yesterday main class was called "Interface" instead of "Account").

@sabyasachiDs
Copy link
Author

Hi,Thanks for the update.Now its working fine.
just i want to ask what other methods are there to generate lighthouse report,Performance Metrics,waterfall report?

@Lex-2008
Copy link
Owner

Lex-2008 commented Sep 2, 2021

I'm not really sure what you mean under "generate", so will just tell you what I know:

Numbers which you see on the "Performance" tab when you open a report on gtmetrix.com website are available under "attributes" of the report. For example, "First Contentful Paint" is available under report["attributes"]["first_contentful_paint"], and "Fully Loaded Time" is under report["attributes"]["fully_loaded_time"]. When you run the example from the main page, the print(json.dumps(report, indent=2)) line prints all these values in a JSON view.

Lighthouse report comes in a JSON format and you can download it with report.getresource("lighthouse.json", …). If you add a second argument - it will be saved to a file with this name: report.getresource("lighthouse.json", "lighthouse-report-for-example.com-site.json") creates a file lighthouse-report-for-example.com-site.json. Alternatively, if you don't pass second argument to the getresource function, you can assign it to a variable and use in your program: lighthouse_report = report.getresource("lighthouse.json")

Waterfall report is a harder beast: as I understand, nice graph that we see on the "Waterfall" report tab is rendered by a script on that page and is not available for API. The best you can do is to download the "net.har" resource and extract required data from it. It's also a JSON.

Note that if you want to process any of these resources (lighthouse.json or net.har) inside your program, you need first to decode() and json.loads them - like shown in this commit.

Alternatively, you can get "report.pdf" resource which is a ready-to-print PDF file with all data you can find on the gtmetrix.com website.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants