Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def google_api_key(monkeypatch):
key = os.environ.get('GOOGLE_API_KEY')
if not key:
pytest.skip("Need GOOGLE_API_KEY environment variable")
monkeypatch.setitem(pmxbot.config, 'Google API key', key)
def _setup_logging():
log_level = pmxbot.config.get('log level', logging.INFO)
if isinstance(log_level, str):
log_level = getattr(logging, log_level.upper())
logging.basicConfig(level=log_level, format="%(message)s")
def __contains__(self, channel):
return channel in pmxbot.config.log_channels
def log_join(nick, channel):
if channel not in pmxbot.config.log_channels:
return
ParticipantLogger.store.log_join(nick, channel)
def on_join(self, connection, event):
nick = event.source.nick
channel = event.target
client = connection
for handler in core.JoinHandler._registry:
try:
handler.attach(locals())()
except Exception:
log.exception("Error in %s", handler)
if channel not in pmxbot.config.log_channels:
return
if nick == self._nickname:
return
self.warn_history.warn(nick, connection)
def google(rest):
"Look up a phrase on google"
API_URL = 'https://www.googleapis.com/customsearch/v1?'
try:
key = pmxbot.config['Google API key']
except KeyError:
return "Configure 'Google API key' in config"
# Use a custom search that searches everything normally
# http://stackoverflow.com/a/11206266/70170
custom_search = '004862762669074674786:hddvfu0gyg0'
params = dict(key=key, cx=custom_search, q=rest.strip())
url = API_URL + urllib.parse.urlencode(params)
resp = requests.get(url)
resp.raise_for_status()
results = resp.json()
hit1 = next(iter(results['items']))
return ' - '.join((urllib.parse.unquote(hit1['link']), hit1['title']))
def _get_wrapper():
"""
Get a socket wrapper based on SSL config.
"""
if not pmxbot.config.get('use_ssl', False):
return lambda x: x
return importlib.import_module('ssl').wrap_socket