From 85f3d0cc010e37823fe5a2895b3ba003fa6725cf Mon Sep 17 00:00:00 2001 From: Marcel Schneider Date: Sun, 4 Feb 2018 19:25:26 +0100 Subject: [PATCH] Better handling of encoding and day of week --- bot.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/bot.py b/bot.py index 2f3ab27..36dd4a5 100755 --- a/bot.py +++ b/bot.py @@ -2,15 +2,13 @@ """ Code for schneiderbot """ -import os +import logging import datetime +import random # import urllib.request # import json import requests -import logging -import random -import discord from discord.ext import commands logging.basicConfig(level=logging.INFO) @@ -61,11 +59,12 @@ async def mensa(which="zentral"): # Es ist zu spät am Tag, zeig das essen für morgen an today += 1 - # with urllib.request.urlopen("https://mensa.schneider-hosting.de/static/%s.%d.json" % (MENSA_URL[which], today)) as url: - # print(url.read().decode()) - # data = json.loads(url.read().decode()) + today = today % 7 - data = requests.get("https://mensa.schneider-hosting.de/static/%s.%d.json" % (MENSA_URL[which], today)).json() + url = "https://mensa.schneider-hosting.de/static/%s.%d.json" % (MENSA_URL[which], today) + request = requests.get(url) + request.encoding = 'utf-8' + data = request.json() await BOT.say("Das Essen für %s in der %s" % (data["date"], MENSA_NAME[which]))