in msticpy/sectools/domain_utils.py [0:0]
def screenshot(url: str, api_key: str = None) -> requests.models.Response:
"""
Get a screenshot of a url with Browshot.
Parameters
----------
url : str
The url a screenshot is wanted for.
api_key : str (optional)
Browshot API key. If not set msticpyconfig checked for this.
Returns
-------
image_data: requests.models.Response
The final screenshot request response data.
"""
# Get Browshot API key from kwargs or config
if api_key is not None:
bs_api_key: Optional[str] = api_key
else:
bs_conf = config.settings.get("DataProviders", {}).get(
"Browshot"
) or config.settings.get("Browshot")
bs_api_key = None
if bs_conf is not None:
bs_api_key = bs_conf.get("Args", {}).get("AuthKey") # type: ignore
if bs_api_key is None:
raise MsticpyUserConfigError(
"No configuration found for Browshot",
"Please add a section to msticpyconfig.yaml:",
"DataProviders:",
" Browshot:",
" Args:",
" AuthKey: {your_auth_key}",
title="Browshot configuration not found",
browshot_uri=("Get an API key for Browshot", "https://api.browshot.com/"),
)
# Request screenshot from Browshot and get request ID
id_string = f"https://api.browshot.com/api/v1/screenshot/create?url={url}/&instance_id=26&size=screen&cache=0&key={bs_api_key}" # pylint: disable=line-too-long
id_data = requests.get(id_string)
bs_id = json.loads(id_data.content)["id"]
status_string = (
f"https://api.browshot.com/api/v1/screenshot/info?id={bs_id}&key={bs_api_key}"
)
image_string = f"https://api.browshot.com/api/v1/screenshot/thumbnail?id={bs_id}&zoom=50&key={bs_api_key}" # pylint: disable=line-too-long
# Wait until the screenshot is ready and keep user updated with progress
print("Getting screenshot")
progress = IntProgress(min=0, max=40)
display.display(progress)
ready = False
while not ready:
progress.value += 1
status_data = requests.get(status_string)
status = json.loads(status_data.content)["status"]
if status == "finished":
ready = True
else:
time.sleep(0.05)
progress.value = 40
# Once ready get the screenshot
image_data = requests.get(image_string)
if image_data.status_code != 200:
print(
"There was a problem with the request, please check the status code for details"
)
return image_data