refactor to be uber profesh

This commit is contained in:
lza_menace 2020-09-23 12:11:16 -07:00
parent c91ef2b935
commit 101ec90dbb
1 changed files with 13 additions and 11 deletions

View File

@ -892,8 +892,10 @@ def weather(bot, trigger):
@sopel.module.commands('yeezy')
def yeezy(bot, trigger):
try:
res = requests.get('https://api.kanye.rest')
bot.say(res.json()['quote'])
except Exception as e:
bot.say('borked: {}'.format(e)
headers = {'User-Agent': 'monerobux-irc-bot-#wownero'}
resp = requests.get('https://api.kanye.rest', headers=headers, timeout=3)
resp.raise_for_status()
blob = resp.json()
if 'quote' not in blob or not isinstance(blob['quote'], str):
raise Exception('malformed response')
bot.say(blob['quote'])