<commit_before>from http import HTTPStatus
from urllib.parse import urljoin

from requests.exceptions import RequestException

from flexget import plugin
from flexget.event import event
from flexget.plugin import PluginWarning
from flexget.utils.requests import Session as RequestSession

plugin_name = 'gotify'

requests = RequestSession(max_retries=3)


class GotifyNotifier(object):
    """
    Example::

    notify:
      entries:
        via:
          - gotify:
              url: <GOTIFY_SERVER_URL>
              token: <GOTIFY_TOKEN>
              priority: <PRIORITY>
    Configuration parameters are also supported from entries (eg. through set).
    """

    schema = {
        'type': 'object',
        'properties': {
            'url': {'format': 'url'},
            'token': {'type': 'string'},
            'priority': {'type': 'integer', 'default': 4},
            'content_type': {'type': 'string', 'enum': ['text/plain', 'text/markdown'], 'default': 'text/plain'},
        },
        'required': ['token', 'url'],
        'additionalProperties': False,
    }

    def notify(self, title, message, config):
        """
        Send a Gotify notification
        """
        base_url = config['url']
        api_endpoint = '/message'
        url = urljoin(base_url, api_endpoint)
        params = {'token': config['token']}

        priority = config['priority']
        content_type = config['content_type']

        notification = {
            'title': title,
            'message': message,
            'priority': priority,
            'extras': {'client::display': {'contentType': content_type}},
        }
        # Make the request
        try:
            response = requests.post(url, params=params, json=notification)
        except RequestException as e:<commit_msg>[pre-commit.ci] auto fixes from pre-commit.com hooks<commit_after>from http import HTTPStatus
from urllib.parse import urljoin

from requests.exceptions import RequestException

from flexget import plugin
from flexget.event import event
from flexget.plugin import PluginWarning
from flexget.utils.requests import Session as RequestSession

plugin_name = 'gotify'

requests = RequestSession(max_retries=3)


class GotifyNotifier(object):
    """
    Example::

    notify:
      entries:
        via:
          - gotify:
              url: <GOTIFY_SERVER_URL>
              token: <GOTIFY_TOKEN>
              priority: <PRIORITY>
    Configuration parameters are also supported from entries (eg. through set).
    """

    schema = {
        'type': 'object',
        'properties': {
            'url': {'format': 'url'},
            'token': {'type': 'string'},
            'priority': {'type': 'integer', 'default': 4},
            'content_type': {
                'type': 'string',
                'enum': ['text/plain', 'text/markdown'],
                'default': 'text/plain',
            },
        },
        'required': ['token', 'url'],
        'additionalProperties': False,
    }

    def notify(self, title, message, config):
        """
        Send a Gotify notification
        """
        base_url = config['url']
        api_endpoint = '/message'
        url = urljoin(base_url, api_endpoint)
        params = {'token': config['token']}

        priority = config['priority']
        content_type = config['content_type']

        notification = {
            'title': title,
            'message': message,
            'priority': priority,
            'extras': {'client::display': {'contentType': content_type}},
        }
        # Make the request
        try:
            response = requests.post(url, params=params, json=notification)
        except RequestException as e:
{'fraction_non_alphanumeric': 0.12642122360584732, 'fraction_numerical': 0.0010828370330265296, 'mean_word_length': 2.229895104895105, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3391473', 'n_tokens_mistral': 994, 'n_tokens_neox': 971, 'n_words': 266}