forked from rohieb/supybot-MensaTUBS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 55da42a
Showing
5 changed files
with
372 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This plugin provides the mensa command, which shows the dishes served today in Mensa 1 Katharinenstraße of TU Braunschweig, Germany. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
### | ||
# Copyright (c) 2009, Roland Hieber | ||
# All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are met: | ||
# | ||
# * Redistributions of source code must retain the above copyright notice, | ||
# this list of conditions, and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above copyright notice, | ||
# this list of conditions, and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# * Neither the name of the author of this software nor the name of | ||
# contributors to this software may be used to endorse or promote products | ||
# derived from this software without specific prior written consent. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
# POSSIBILITY OF SUCH DAMAGE. | ||
|
||
### | ||
|
||
""" | ||
Shows the dishes served today in Mensa 1 | ||
""" | ||
|
||
import supybot | ||
import supybot.world as world | ||
|
||
# Use this for the version of this plugin. You may wish to put a CVS keyword | ||
# in here if you're keeping the plugin in CVS or some similar system. | ||
__version__ = "0.5" | ||
|
||
# XXX Replace this with an appropriate author or supybot.Author instance. | ||
__author__ = supybot.Author('Roland Hieber', 'rohieb') | ||
|
||
# This is a dictionary mapping supybot.Author instances to lists of | ||
# contributions. | ||
__contributors__ = {} | ||
|
||
# This is a url where the most recent plugin package can be downloaded. | ||
__url__ = '' # 'http://supybot.com/Members/yourname/Mensa/download' | ||
|
||
import config | ||
import plugin | ||
reload(plugin) # In case we're being reloaded. | ||
# Add more reloads here if you add third-party modules and want them to be | ||
# reloaded when this plugin is reloaded. Don't forget to import them as well! | ||
|
||
if world.testing: | ||
import test | ||
|
||
Class = plugin.Class | ||
configure = config.configure | ||
|
||
|
||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
### | ||
# Copyright (c) 2009, Roland Hieber | ||
# All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are met: | ||
# | ||
# * Redistributions of source code must retain the above copyright notice, | ||
# this list of conditions, and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above copyright notice, | ||
# this list of conditions, and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# * Neither the name of the author of this software nor the name of | ||
# contributors to this software may be used to endorse or promote products | ||
# derived from this software without specific prior written consent. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
# POSSIBILITY OF SUCH DAMAGE. | ||
|
||
### | ||
|
||
import supybot.conf as conf | ||
import supybot.registry as registry | ||
|
||
def configure(advanced): | ||
# This will be called by supybot to configure this module. advanced is | ||
# a bool that specifies whether the user identified himself as an advanced | ||
# user or not. You should effect your configuration by manipulating the | ||
# registry as appropriate. | ||
from supybot.questions import expect, anything, something, yn | ||
conf.registerPlugin('Mensa', True) | ||
|
||
|
||
Mensa = conf.registerPlugin('Mensa') | ||
# This is where your configuration variables (if any) should go. For example: | ||
#conf.registerGlobalValue(Mensa, 'someConfigVariableName', | ||
# registry.Boolean(False, """Help for someConfigVariableName.""")) | ||
conf.registerChannelValue(Mensa, 'multiline', registry.Boolean(False, | ||
"""Determines if the output is printed in one line or in multiple lines. | ||
One line means less spam, multiple lines means easier to read.""")) | ||
|
||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
# vim:fileencoding=utf8 | ||
### | ||
# Copyright (c) 2009, Roland Hieber | ||
# All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are met: | ||
# | ||
# * Redistributions of source code must retain the above copyright notice, | ||
# this list of conditions, and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above copyright notice, | ||
# this list of conditions, and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# * Neither the name of the author of this software nor the name of | ||
# contributors to this software may be used to endorse or promote products | ||
# derived from this software without specific prior written consent. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
# POSSIBILITY OF SUCH DAMAGE. | ||
|
||
### | ||
|
||
import supybot.utils as utils | ||
from supybot.commands import * | ||
import supybot.plugins as plugins | ||
import supybot.ircutils as ircutils | ||
import supybot.callbacks as callbacks | ||
import urllib; | ||
import datetime; | ||
|
||
class Mensa(callbacks.Plugin): | ||
"""Provides the mensa command, which shows the dishes served | ||
today in the Mensa.""" | ||
pass | ||
|
||
additives = { "1": "mit Farbstoff", "2": "mit Konservierungsstoff", | ||
"3": "mit Antioxidationsmittel", "4": "mit Geschmacksverstärker", | ||
"5": "geschwefelt", "6": "geschwärzt", "7": "gewachst", "8": "mit Phosphat", | ||
"9": "mit Süßungsmittel", "10": "enthält eine Phenylalaninquelle", | ||
"11": "Milcheiweiß", "12": "koffeinhaltig", "13": "chininhaltig", | ||
"14": "mit Taurin", "S": "mit Schweinefleisch", "R": "mit Rindfleisch", | ||
"O": "ohne Schweinefleisch", "V": "vegetarisch" } | ||
|
||
weekdays = { 0: "mo", 1: "di", 2: "mi", 3: "do", 4: "fr", 5: "sa", 6: "mo" } | ||
weekdaysPrintable = { "mo": "Montag", "di": "Dienstag", "mi": "Mittwoch", | ||
"do": "Donnerstag", "fr": "Freitag", "sa": "Samstag" } | ||
|
||
def __init__(self, irc): | ||
self.__parent = super(Mensa, self) | ||
self.__parent.__init__(irc) | ||
|
||
# mensa is one of { "kath", "beeth", "abend", "hbk" } | ||
# day is one of { "mo","di","mi","do","fr","sa","sa","tomorrow","today" } | ||
# return list of strings or False in case of error | ||
def _mensa(self, mensa = None, day = None, multiline = False): | ||
hour = datetime.datetime.now().time().hour | ||
|
||
if mensa == "3": | ||
return [ "türkis Döner:", "Dönertasche: 3,50€", "Dönerbox: 2,50€" ] | ||
|
||
# TODO move checks to mensa() so this function only loads the data | ||
# check mensa | ||
if mensa == None: | ||
# show abendmensa from 3pm to 8pm | ||
if hour >= 15 and hour < 20 and day == None: | ||
mensa = "abend" | ||
elif hour >= 20 and day == None: | ||
day = "tomorrow" | ||
mensa = "kath" | ||
else: | ||
mensa = "kath" | ||
|
||
# check day | ||
if day == None: | ||
day = "today"; | ||
|
||
if day == "today": | ||
dow = self.weekdays[datetime.datetime.now().weekday()] | ||
elif day == "tomorrow": | ||
dow = self.weekdays[(datetime.datetime.now().weekday() + 1) % 7] | ||
else: | ||
dow = day | ||
|
||
#print "_mensa(): mensa=%s, dow=%s" % (mensa, dow) | ||
|
||
# all input is evil | ||
if dow not in ["mo","di","mi","do","fr","sa"]: | ||
return False | ||
if mensa not in ["kath", "beeth", "abend", "hbk"]: | ||
return False | ||
|
||
# saturdays only in kath, otherwise http 404 | ||
if dow == "sa" and mensa != "kath": | ||
return [ "Nothing." ] | ||
|
||
urlpart = mensa | ||
if mensa == "abend": | ||
urlpart = "kath" | ||
|
||
# fetch data from external site | ||
urlfile = dow + ".csv" | ||
url = "http://www.trivalg.de/mensa/" + urlpart + "/" + urlfile | ||
|
||
#print "Fetching "+url | ||
f = urllib.urlopen(url) | ||
s = f.read() | ||
#s = s.decode('iso-8859-1').encode('utf-8') | ||
f.close() | ||
|
||
# kath and abend are in the same file, so look for Mittagsmensa / Abendmensa | ||
newlines = [] | ||
for line in s.splitlines(): | ||
if line == "Mittagsmensa": | ||
continue | ||
if line == "Abendsmensa": | ||
if mensa != "abend": | ||
break | ||
elif mensa == "abend": | ||
newlines = [] | ||
continue | ||
newlines.append(line) | ||
|
||
# build list with reply string | ||
heading = "" | ||
if mensa == "beeth": | ||
heading = "Mensa Beethovenstraße" | ||
elif mensa == "hbk": | ||
heading = "Mensa HBK" | ||
elif mensa == "kath": | ||
heading = "Mensa Katharinenstraße" | ||
elif mensa == "abend": | ||
heading = "Abendmensa Katharinenstraße" | ||
|
||
heading += " am " + self.weekdaysPrintable[dow] + ": " | ||
rply = [ heading ]; | ||
|
||
for line in newlines: | ||
if line.startswith("Gibt es nicht"): | ||
return [ "Nothing." ] | ||
cols = line.split(';') | ||
if len(cols) > 1: | ||
if multiline: | ||
rply.append(cols[0].strip() + " " + cols[2].strip() + "€") | ||
else: | ||
rply.append(cols[0].strip() + " " + cols[2].strip() + "€ //") | ||
|
||
return rply | ||
|
||
def mensa(self, irc, msg, args, argstring): | ||
"""[<mensa>] [<time>] | ||
Shows the dishes served today in <mensa>. <mensa> is one of "kath" | ||
(default) for Mensa 1 (Katharinenstraße), "beeth" for Mensa 2 | ||
(Beethovenstraße), "hbk" for Mensa HBK or "abend" for Abendmensa | ||
(Katharinenstraße, default for times between 3pm and 8pm). | ||
<time> specifies the time to show, can be one of "mo", "di", "mi", "do", | ||
"fr", "sa" for the respective weekdays, or "today"/"heute" (default), | ||
"tomorrow"/"morgen" for todays resp. tomorrows dishes. From 8pm on, the | ||
dishes for the next day are shown. | ||
""" | ||
|
||
multiline = self.registryValue('multiline', | ||
plugins.getChannel(msg.args[0])); | ||
|
||
# parse parameters if given | ||
day = None | ||
mensa = None | ||
if argstring and len(argstring) > 0: | ||
arglist = argstring.split(" ") | ||
for argn in arglist: | ||
# translate to english :P | ||
if argn.strip() == "morgen": | ||
day = "tomorrow" | ||
elif argn.strip() == "heute": | ||
day = "today" | ||
elif argn.strip() in ["mo","di","mi","do","fr","sa","today","tomorrow"]: | ||
day = argn; | ||
|
||
if argn.strip() in ["kath","beeth","abend","hbk","3"]: | ||
mensa = argn; | ||
elif argn.strip().rfind("1") != -1: | ||
mensa = "kath"; | ||
elif argn.strip().rfind("2") != -1: | ||
mensa = "beeth"; | ||
|
||
#print "calling mensa with mensa=%s,day=%s,multiline=%d" % (mensa, day, multiline) | ||
|
||
rply = self._mensa(mensa, day, multiline) | ||
|
||
if rply == False: | ||
irc.reply("Error in parameters. See help for this command.") | ||
return | ||
|
||
# do reply | ||
if multiline: | ||
for s in rply: | ||
irc.reply(s, prefixNick = False) | ||
else: | ||
irc.reply(" ".join(rply), prefixNick = False) | ||
|
||
mensa = wrap(mensa, [additional('text')]) | ||
|
||
#def zusatz(self, irc, msg, args): | ||
#zusatz = wrap(zusatz, []) | ||
|
||
Class = Mensa | ||
|
||
|
||
# vim:set shiftwidth=2 tabstop=2 expandtab textwidth=79: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
### | ||
# Copyright (c) 2009, Roland Hieber | ||
# All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are met: | ||
# | ||
# * Redistributions of source code must retain the above copyright notice, | ||
# this list of conditions, and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above copyright notice, | ||
# this list of conditions, and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# * Neither the name of the author of this software nor the name of | ||
# contributors to this software may be used to endorse or promote products | ||
# derived from this software without specific prior written consent. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
# POSSIBILITY OF SUCH DAMAGE. | ||
|
||
### | ||
|
||
from supybot.test import * | ||
|
||
class MensaTestCase(PluginTestCase): | ||
plugins = ('Mensa',) | ||
|
||
|
||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: |