Browse Source

Better handling of encoding and day of week

master
Schneider 7 years ago
parent
commit
85f3d0cc01
  1. 15
      bot.py

15
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]))

Loading…
Cancel
Save