Beispiel #1
0
    def create(self, config_section):
        updater = ImageNotificationUpdater()

        has_images = "images" in config_section
        has_default_image = "default-image" in config_section

        if not has_images and not has_default_image:
            raise MissingRequiredOptionException(
                "Expected 'images' list and/or default-image to exist")

        if has_default_image:
            image_url = self._encode_url(config_section["default-image"])

            image_path = self.download(image_url)
            updater.add_image_filter(image_path)

        if has_images:
            for image_config_section in config_section["images"]:
                if "path" not in image_config_section:
                    raise MissingRequiredOptionException(
                        "Expected 'path' option to exist")

                image_url = self._encode_url(image_config_section["path"])

                image_filter = self._create_filter(image_config_section)
                image_path = self.download(image_url)

                updater.add_image_filter(image_path, image_filter)

        return updater
Beispiel #2
0
    def create(self, config_section):
        if "token" not in config_section:
            raise MissingRequiredOptionException(
                "Expected 'token' option to exist")

        if "channel" not in config_section:
            raise MissingRequiredOptionException(
                "Expected 'channel' option to exist")

        slack_client = SlackClient(config_section["token"])
        channel = config_section["channel"]
        return SlackFeed(slack_client, channel)
Beispiel #3
0
    def create(self, config_section):
        if "url" not in config_section:
            raise MissingRequiredOptionException(
                "Expected 'url' option to exist")

        url = config_section["url"]
        sort_order = None
        if "sort" in config_section:
            if config_section["sort"] not in ["newest", "oldest"]:
                raise MissingRequiredOptionException(
                    "Sorting value for RSS feed can only be either ascending or descending"
                )

            sort_order = config_section["sort"]

        return RssFeed(url, sort_order)
Beispiel #4
0
    def _create_filter(image_config_section):
        pattern_exists = "if-matches" in image_config_section
        contains_exists = "if-contains" in image_config_section

        if not pattern_exists and not contains_exists:
            raise MissingRequiredOptionException(
                "Expected either 'if-contains' or 'if-matches' option to exist"
            )

        if pattern_exists and contains_exists:
            raise MissingRequiredOptionException(
                "Expected either 'if-contains' or 'if-matches' option, but not both"
            )

        if pattern_exists:
            return MatchesRegexFilter(image_config_section["if-matches"])
        else:
            return ContainsTextFilter(image_config_section["if-contains"])
    def create(self, config_section):
        if "text" not in config_section:
            raise MissingRequiredOptionException(
                "Expected 'text' option to exist")

        return ContainsTextFilter(str(config_section["text"]))
    def create(self, config_section):
        if "pattern" not in config_section:
            raise MissingRequiredOptionException(
                "Expected 'pattern' option to exist")

        return MatchesRegexFilter(str(config_section["pattern"]))