Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pylacus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
else:
from deprecated import deprecated

from .api import PyLacus, CaptureStatus, CaptureResponse, CaptureResponseJson # noqa
from .api import PyLacus, CaptureStatus, SessionStatus, CaptureResponse, CaptureResponseJson, InteractiveSessionResponse # noqa


@deprecated("Use lookyloo-models instead, the Pydantic models.")
Expand Down Expand Up @@ -42,6 +42,8 @@ class CaptureSettings(TypedDict, total=False):
with_trusted_timestamps: bool
allow_tracking: bool
headless: bool
interactive: bool
interactive_ttl: int
init_script: str

force: bool | None
Expand All @@ -58,8 +60,10 @@ class CaptureSettings(TypedDict, total=False):
__all__ = [
'PyLacus',
'CaptureStatus',
'SessionStatus',
'CaptureResponse',
'CaptureResponseJson',
'InteractiveSessionResponse',
'CaptureSettings'
]

Expand Down
42 changes: 41 additions & 1 deletion pylacus/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,30 @@
BROWSER = Literal['chromium', 'firefox', 'webkit']


@unique
class SessionStatus(IntEnum):
'''The status of an interactive session'''
UNKNOWN = -1
STARTING = 0
READY = 1
ERROR = 2
STOPPED = 3
EXPIRED = 4
CAPTURE_REQUESTED = 5


class InteractiveSessionResponse(TypedDict, total=False):
'''Response from the interactive session status and finish endpoints.'''
uuid: str
status: str
raw_status: int
finish_requested: bool
view_url: str | None
created_at: int
expires_at: int
error: str | None


class FramesResponse(TypedDict, total=False):

name: str
Expand Down Expand Up @@ -145,6 +169,8 @@ def enqueue(self, *,
with_trusted_timestamps: bool=False,
allow_tracking: bool=False,
headless: bool=True,
interactive: bool=False,
interactive_ttl: int=600,
init_script: str | None=None,
rendered_hostname_only: bool=True,
force: bool=False,
Expand Down Expand Up @@ -181,6 +207,8 @@ def enqueue(self, *,
with_trusted_timestamps: bool=False,
allow_tracking: bool=False,
headless: bool=True,
interactive: bool=False,
interactive_ttl: int=600,
init_script: str | None=None,
rendered_hostname_only: bool=True,
force: bool=False,
Expand All @@ -205,7 +233,9 @@ def enqueue(self, *,
'with_screenshot': with_screenshot, 'with_favicon': with_favicon,
'with_trusted_timestamps': with_trusted_timestamps,
'allow_tracking': allow_tracking, 'final_wait': final_wait,
'headless': headless, 'init_script': init_script,
'headless': headless, 'interactive': interactive,
'interactive_ttl': interactive_ttl,
'init_script': init_script,
'max_retries': max_retries, 'force': force,
'recapture_interval': recapture_interval,
'priority': priority, 'uuid': uuid
Expand All @@ -225,6 +255,16 @@ def get_capture_status(self, uuid: str) -> CaptureStatus:
r = self.session.get(urljoin(self.root_url, str(PurePosixPath('capture_status', uuid))))
return r.json()

def get_interactive_session(self, uuid: str) -> InteractiveSessionResponse:
'''Get the status and public view details for an interactive capture session.'''
r = self.session.get(urljoin(self.root_url, str(PurePosixPath('interactive', uuid))))
return r.json()

def request_interactive_capture(self, uuid: str) -> InteractiveSessionResponse:
'''Request a final capture of the current page for an interactive session.'''
r = self.session.post(urljoin(self.root_url, str(PurePosixPath('interactive', uuid, 'finish'))))
return r.json()

def _decode_response(self, capture: CaptureResponseJson) -> CaptureResponse:
decoded_capture = cast(CaptureResponse, capture)
if capture.get('png') and capture['png']:
Expand Down