Module scrapfly.reporter

Expand source code
from typing import Tuple, Callable, Optional
from .NoopReporter import NoopReporter
from .PrintReporter import PrintReporter
from .ChainReporter import ChainReporter

__all__:Tuple[str, ...] = (
    'NoopReporter',
    'PrintReporter',
    'ChainReporter'
)

from .. import ScrapflyError, ScrapeApiResponse


class Reporter:

    reporter:Callable

    def __init__(self, reporter:Callable):
        self.reporter = reporter

    def report(self, error:Optional[BaseException]=None, scrape_api_response:Optional[ScrapeApiResponse]=None):
        api_response = scrape_api_response

        if error is not None and api_response is None and isinstance(error, ScrapflyError):
            api_response:Optional[ScrapeApiResponse] = error.api_response

        self.reporter(error, api_response)

Sub-modules

scrapfly.reporter.SentryReporter

Classes

class ChainReporter (*args: Tuple[Callable])
Expand source code
class ChainReporter:
    reporters: Tuple[Callable]

    def __init__(self, *args:Tuple[Callable]):
        self.reporters = args

    def __call__(self, error:Optional[Exception]=None, scrape_api_response:Optional[ScrapeApiResponse]=None):
        [reporter(error, scrape_api_response) for reporter in self.reporters]

Class variables

var reporters : Tuple[Callable]
class NoopReporter
Expand source code
class NoopReporter:

    def __call__(self, error:Optional[Exception]=None, scrape_api_response:Optional[ScrapeApiResponse]=None):
        pass
class PrintReporter
Expand source code
class PrintReporter:

    def __call__(self, error:Optional[Exception]=None, scrape_api_response:Optional[ScrapeApiResponse]=None):
        debug_data = {
            'scrape_config': None,
            'log_url': None,
            'scrape_error': None,
            'error': None
        }

        if scrape_api_response:
            debug_data['scrape_config'] = scrape_api_response.config

            if scrape_api_response.error is not None:
                debug_data['scrape_error'] = scrape_api_response.error

            if scrape_api_response.scrape_result:
                debug_data['log_url'] = scrape_api_response.scrape_result['log_url']

        if error is not None:
            debug_data['error'] = {
                'message': str(error),
                'type': error.__class__.__name__
            }

        pprint(debug_data)