def get_logger(name=None): """Return a logger for a module, if the name is given. .. deprecated:: 7.0 Use ``logging.getLogger(__name__)`` in Sopel's code instead, and :func:`sopel.tools.get_logger` for external plugins. This will warn a deprecation warning in Sopel 8.0 then removed in 9.0. """ if not name: return logging.getLogger('sopel') parts = name.strip().split('.') if len(parts) > 1 or parts[0] in ['sopel', 'sopel_modules']: return logging.getLogger(name) # assume it's a plugin name, as intended by the original get_logger return tools.get_logger(name)
def get_logger(name=None): """Return a logger for a module, if the name is given. .. deprecated:: 7.0 Sopel's own code should use :func:`logging.getLogger(__name__) <logging.getLogger>` instead, and external plugins should use :func:`sopel.tools.get_logger`. This will emit a deprecation warning in Sopel 8.0, and it will be removed in Sopel 9.0. """ if not name: return logging.getLogger('sopel') parts = name.strip().split('.') if len(parts) > 1 or parts[0] in ['sopel', 'sopel_modules']: return logging.getLogger(name) # assume it's a plugin name, as intended by the original get_logger return tools.get_logger(name)
"""Help providers.""" import hashlib import os import socket import urllib import requests from sopel.tools import get_logger from sopel_help import mixins LOGGER = get_logger('help') class PublishingError(Exception): """Generic publishing error.""" class UnknownCommand(Exception): """Command is unknown.""" def _post_content(*args, **kwargs): try: response = requests.post(*args, **kwargs) response.raise_for_status() except ( requests.exceptions.Timeout, requests.exceptions.TooManyRedirects, requests.exceptions.RequestException, requests.exceptions.HTTPError
from urllib.parse import quote_plus import html from html.parser import HTMLParser import re import requests import pendulum ### # Module config/setup/shutdown ### LOGGER = get_logger(__name__) API_CHANNELS_URL = "https://somafm.com/channels.json" API_SONGS_URL = "https://somafm.com/songs/{}.json" class MLStripper(HTMLParser): def __init__(self): super().__init__() self.reset() self.fed = [] def handle_data(self, d): self.fed.append(d) def get_data(self): return ''.join(self.fed)
"""phab.by - Phabricator Task Information Plugin""" import requests # FIX THIS from sopel.module import commands, example, interval, rule, require_admin from sopel.config.types import StaticSection, ValidatedAttribute, ListAttribute from json import JSONDecodeError from sopel.tools import get_logger, SopelMemory from sopel.config import ConfigurationError from MirahezeBots.utils import jsonparser as jp from urllib.parse import urlparse LOGGER = get_logger('phabricator') class PhabricatorSection(StaticSection): host = ValidatedAttribute('host', str) api_token = ListAttribute('api_token', str) querykey = ListAttribute('querykey', str) highpri_notify = ValidatedAttribute('highpri_notify', bool) highpri_channel = ValidatedAttribute('highpri_channel', str) datafile = ValidatedAttribute('datafile', str) def setup(bot): bot.config.define_section('phabricator', PhabricatorSection) if bot.settings.phabricator.host and bot.settings.phabricator.datafile: raise ConfigurationError( "Use of host and datafile together is not supported") elif bot.settings.phabricator.host: LOGGER.warn( "Use of the host option was deceprated in 9.0.0 and will be removed in 10.0.0" )
ValidatedAttribute, ChoiceAttribute, NO_DEFAULT, ) from sopel.formatting import color, colors, bold from sopel.module import commands, example, NOLIMIT from sopel import tools from sopel.modules.units import c_to_f, f_to_c from sopel.tools.time import (format_time, get_channel_timezone, get_nick_timezone, get_timezone, validate_timezone) import pendulum import requests LOGGER = tools.get_logger(__name__) WEATHER_CODE_DESCRIPTIONS = { "rain_heavy": "🌧️ Substantial rain", "rain": "🌧️ Rain", "rain_light": "🌧️ Light rain", "freezing_rain_heavy": "🧊🌧️ Substantial freezing rain", "freezing_rain": "🧊🌧️ Freezing rain", "freezing_rain_light": "🧊🌧️ Light freezing rain", "freezing_drizzle": "🧊🌧️ Light freezing rain falling in fine pieces", "drizzle": "🌦️ Drizzle", "ice_pellets_heavy": "🧊 Substantial ice pellets", "ice_pellets": "🧊 Ice pellets", "ice_pellets_light": "🧊 Light ice pellets", "snow_heavy": "❄️ Substantial snow", "snow": "❄️ Snow",
import flag import pendulum import requests from sopel_sopel_plugin_argparser import parseargs from sopel import module, tools from sopel.formatting import bold, color, colors, underline from sopel.tools.time import (format_time, get_channel_timezone, get_nick_timezone, get_timezone, validate_timezone) # import shlex LOGGER = tools.get_logger("mma") schedule_url = "https://www.espn.com/mma/schedule/_/year/2021?_xhr=pageContent" event_url = ("https://site.web.api.espn.com/apis/common/v3/sports/mma/ufc" "/fightcenter/{event_id}?region=us&lang=en&contentorigin=espn" "&showAirings=buy%2Clive%2Creplay&buyWindow=1m") fighter_search_url = ( "https://site.api.espn.com/apis/common/v3/search?xhr=1&query={query}" "&limit=5&type=player&sport=mma&mode=prefix&lang=en®ion=us") fighter_search_news_url = ( "https://site.api.espn.com/apis/common/v3/search?xhr=1&query={query}" "&limit=5&type=article&sport=mma&mode=prefix&lang=en®ion=us") fighter_news_url = ( "https://api-app.espn.com/allsports/apis/v1/now?region=us&lang=en" "&contentorigin=espn&limit=3&content=story%2Cblog%2Crecap%2Ctheundefeated%2Cfivethirtyeight" "&contentcategories={player_id}"
# -*- coding: utf-8 -*- import argparse from datetime import datetime from pyowm import OWM # from pyowm.exceptions.api_response_error import NotFoundError, UnauthorizedError # from pyowm.exceptions.api_call_error import APICallError from sopel import module from sopel import plugin, tools # type: ignore from sopel.bot import Sopel, SopelWrapper # type: ignore from sopel.config import Config # type: ignore from sopel.trigger import Trigger # type: ignore from .utils import OWMSection, get_api, parse_location_args, get_weather_message, get_owm_location log = tools.get_logger('openweathermap') # --- Sopel Setup Section --- def configure(config): log.debug(type(config)) config.define_section("owm", OWMSection) config.owm.configure_setting( "api_key", "What is your OpenWeatherMap.org API Key or APPID?") def setup(bot: SopelWrapper) -> None: """ Ensures that our set up configuration items are present """ # Ensure configuration bot.config.define_section('owm', OWMSection)