Skip to content

[FEATURE] Support custom reporters #24

@knutwannheden

Description

@knutwannheden

Is your feature request related to a problem? Please describe.
I've been using urlwatch up until now and just discovered this fork. Very nice! One crucial feature that is missing however is support for custom reporters. urlwatch supports this through the --hooks option. While it appears I can also with webchanges specify this option, it later tells me that the corresponding configuration in the file referenced by --config is invalid.

Here is the error that was reported:

ValueError: Unrecognized directive(s) in the configuration file urlwatch-errors.yaml:
report:
  custom_slack:
    channel: C02PC0NG111
    enabled: false
    token: xoxb-aaaaaaaaaaa-bbbbbbbbbbbbb-ffffffffffffffffffffffff

Describe the solution you'd like
I would like to be able to configure my custom reporters using the YAML config file as with urlwatch.

Describe alternatives you've considered
If webchanges supports some equivalent alternative that I missed, then that of course also works for me.

Additional context
And for completeness sake here is my hooks.py file:

from datetime import datetime

from slack_sdk import WebClient
from urlwatch import reporters


class CustomSlackReporter(reporters.TextReporter):
    """Custom Slack reporter that uploads diff as file to Slack"""

    __kind__ = 'custom_slack'

    def submit(self):
        text = '\n'.join(super().submit())
        if text:
            slack_token = self.config['token']
            client = WebClient(token=slack_token)
            timestamp = datetime.now().strftime("%d.%m.%Y %H:%M:%S")
            response = client.files_upload(
                channels=self.config['channel'],
                filetype="diff",
                content=text,
                initial_comment="Report " + timestamp,
                title=f"report-{datetime.now().strftime('%d.%m.%Y')}.txt"
            )

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions