aboutsummaryrefslogtreecommitdiff
path: root/mensa/backends
diff options
context:
space:
mode:
Diffstat (limited to 'mensa/backends')
-rw-r--r--mensa/backends/base.py43
-rw-r--r--mensa/backends/mathemensa.py6
-rw-r--r--mensa/backends/satyam.py7
-rw-r--r--mensa/backends/singh.py10
-rw-r--r--mensa/backends/studentenwerk.py20
5 files changed, 25 insertions, 61 deletions
diff --git a/mensa/backends/base.py b/mensa/backends/base.py
deleted file mode 100644
index 6c57336..0000000
--- a/mensa/backends/base.py
+++ /dev/null
@@ -1,43 +0,0 @@
-# Common classes and methods.
-
-class Food :
- def __init__(self,name, price="", category="Essen", veggie=False, desc=None, ingredients={}) :
- self.name = name
- self.price = price
- self.category = category
- self.veggie = veggie
- self.desc=desc
- self.ingredients=ingredients
-
-def formt (food) :
- cat = []
- vegkeys = [ "", "Vegetarian", "Vegan" ]
- r = ""
- food.sort(key=lambda foo: foo.category)
- for i in food:
- if not i.category in cat :
- cat.append(i.category)
- if not i.category == None :
- r=r+ i.category+"\n"
- r=r+"\t" + i.name.ljust(80) + "\t"+ i.price.ljust(20) + vegkeys[i.veggie]+"\n"
- if i.desc :
- r = r+"\t "+i.desc+"\n"
- return r
-
-foodsources = {}
-
-class Restaurant(object):
- def __init__(self, name, human_name, module, optional_args=[], obligatory_args=()):
- self.name = name
- self.human_name = human_name
- self.module = module
- self.optional_args = optional_args
- self.obligatory_args = obligatory_args
-
- def get_food(**opt_args) :
- self.module.get_food_items(*obligatory_args, **optional_args)
-
-
-def register_restaurant(restaurant):
- global foodsources
- foodsources[restaurant.name] = (restaurant)
diff --git a/mensa/backends/mathemensa.py b/mensa/backends/mathemensa.py
index 559956d..6fa93ce 100644
--- a/mensa/backends/mathemensa.py
+++ b/mensa/backends/mathemensa.py
@@ -10,7 +10,7 @@ import html5lib
import datetime
from mensa.base import *
from yapsy.IPlugin import IPlugin
-
+from collections import OrderedDict
class Mathemensa(IPlugin) :
def register_restaurants(self) :
r = Restaurant("Mathekantine", "Mathekantine", self, "dummy", pos=(52.51388,13.3235066))
@@ -46,4 +46,6 @@ class Mathemensa(IPlugin) :
if "(v)" in name or "Gemüseplatte" in name :
veg = 1
fl.append(Food(name, price, "Menü", veg))
- return fl
+ d = OrderedDict()
+ d["Menü"] = fl
+ return d
diff --git a/mensa/backends/satyam.py b/mensa/backends/satyam.py
index bf18dc5..6d28209 100644
--- a/mensa/backends/satyam.py
+++ b/mensa/backends/satyam.py
@@ -6,6 +6,7 @@ from mensa.base import *
import re
import sys
from yapsy.IPlugin import IPlugin
+from collections import OrderedDict
class Satyam(IPlugin):
def register_restaurants(self) :
@@ -30,9 +31,9 @@ class Satyam(IPlugin):
name = name.replace("\\n", "")
name = " ".join(name.split())
name = name.replace(price, "")
-
- return [Food("Mittagstisch Express", price, "Mittagstisch", 2, name[3:-1])]
-
+ k = OrderedDict()
+ k["Mittagstisch"] = [Food("Mittagstisch Express", price, "Mittagstisch", 2, name[3:-1])]
+ return k
# if __name__ == "__main__":
# food = get_food_items()
diff --git a/mensa/backends/singh.py b/mensa/backends/singh.py
index 393b5da..3e76190 100644
--- a/mensa/backends/singh.py
+++ b/mensa/backends/singh.py
@@ -7,6 +7,7 @@ import sys
import datetime
from mensa.base import *
from yapsy.IPlugin import IPlugin
+from collections import OrderedDict
class Signh(IPlugin) :
def register_restaurants(self) :
@@ -27,7 +28,7 @@ class Signh(IPlugin) :
the_page = response.read()
document = html5lib.parse(the_page, treebuilder="lxml")
groupsel = CSSSelector('.menu-list__items')
- myorder=[0,3,1,4,2]
+ myorder=[0,3,1,4,2] # Weird order for weekdays, due to page layout.
mylist = [ groupsel(document)[i] for i in myorder]
i = mylist[weekday]
fl = []
@@ -48,9 +49,8 @@ class Signh(IPlugin) :
veg = 2
fl.append(Food(name, price, "Essen", veg, desc))
sys.stderr = s
- return fl
+ k = OrderedDict()
+ k["Essen"] = fl
+ return k
-if __name__ == "__main__":
- food = get_food_items()
- print(formt(food))
diff --git a/mensa/backends/studentenwerk.py b/mensa/backends/studentenwerk.py
index 89c45eb..b1f00fd 100644
--- a/mensa/backends/studentenwerk.py
+++ b/mensa/backends/studentenwerk.py
@@ -9,7 +9,7 @@ from mensa.base import *
from yapsy.IPlugin import IPlugin
import multiprocessing
import datetime
-
+from collections import OrderedDict
from yapsy import NormalizePluginNameForModuleName as normalize
mensenliste = {"TU Hardenbergstraße" : ["mensa-tu-hardenbergstra%C3%9Fe", (52.5097684, 13.3259478)],
@@ -43,18 +43,20 @@ class Studentenwerk(IPlugin) :
for h,n in mensenliste.items() :
r = Restaurant(normalize(h), h, self, "dummy", [n[0]], pos=n[1])
register_restaurant(r)
- def get_food_items(self, mensa="mensa-tu-hardenbergstra%C3%9Fe", ignore_nudelauswahl=False) :
+ def get_food_items(self, mensa="mensa-tu-hardenbergstra%C3%9Fe", ignore_nudelauswahl=False, **options) :
document = self.fetch_page(mensa)
groupsel = CSSSelector('.splGroupWrapper')
groups = [e for e in groupsel(document)]
- fl = []
- for i in groups :
+ fl = OrderedDict()
+ for group in groups :
try:
- name = CSSSelector('.splGroup')(i)[0].text
+ category = CSSSelector('.splGroup')(group)[0].text
except:
- raise NoMenuError from None
+ raise NoMenuError from None
+ if not category in fl :
+ fl[category] = []
sel = CSSSelector('.splMeal')
- meals = [e for e in sel(i)]
+ meals = [e for e in sel(group)]
for m in meals :
namesel = CSSSelector('.bold')
nm = namesel(m)[0].text
@@ -68,7 +70,9 @@ class Studentenwerk(IPlugin) :
elif "1.png" in pricesel(m)[0][1].attrib["src"] :
veg = 1
price = pricesel(m)[-1].text.strip()
- fl.append(Food(nm, price, name, veg))
+ if "only_student_prices" in options and options["only_student_prices"] :
+ price = only_student_prices(price)
+ fl[category].append(Food(nm, price, category, veg))
return fl
def get_opening_hours(self, mensa) :
#### Rudiment of a function for getting opening hours. Does NOT work yet due to unknown issues.
68'>468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
/*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#pragma once

#include "irrlichttypes.h"
#include "irr_v3d.h"
#include <iostream>
#include <cassert>
#include "exceptions.h"
#include "mapnode.h"
#include <set>
#include <list>
#include "util/basic_macros.h"

class NodeDefManager;

// For VC++
#undef min
#undef max

/*
	A fast voxel manipulator class.

	In normal operation, it fetches more map when it is requested.
	It can also be used so that all allowed area is fetched at the
	start, using ManualMapVoxelManipulator.

	Not thread-safe.
*/

/*
	Debug stuff
*/
extern u64 emerge_time;
extern u64 emerge_load_time;

/*
	This class resembles aabbox3d<s16> a lot, but has inclusive
	edges for saner handling of integer sizes
*/
class VoxelArea
{
public:
	// Starts as zero sized
	VoxelArea() = default;

	VoxelArea(const v3s16 &min_edge, const v3s16 &max_edge):
		MinEdge(min_edge),
		MaxEdge(max_edge)
	{
		cacheExtent();
	}

	VoxelArea(const v3s16 &p):
		MinEdge(p),
		MaxEdge(p)
	{
		cacheExtent();
	}

	/*
		Modifying methods
	*/

	void addArea(const VoxelArea &a)
	{
		if (hasEmptyExtent())
		{
			*this = a;
			return;
		}
		if(a.MinEdge.X < MinEdge.X) MinEdge.X = a.MinEdge.X;
		if(a.MinEdge.Y < MinEdge.Y) MinEdge.Y = a.MinEdge.Y;
		if(a.MinEdge.Z < MinEdge.Z) MinEdge.Z = a.MinEdge.Z;
		if(a.MaxEdge.X > MaxEdge.X) MaxEdge.X = a.MaxEdge.X;
		if(a.MaxEdge.Y > MaxEdge.Y) MaxEdge.Y = a.MaxEdge.Y;
		if(a.MaxEdge.Z > MaxEdge.Z) MaxEdge.Z = a.MaxEdge.Z;
		cacheExtent();
	}

	void addPoint(const v3s16 &p)
	{
		if(hasEmptyExtent())
		{
			MinEdge = p;
			MaxEdge = p;
			cacheExtent();
			return;
		}
		if(p.X < MinEdge.X) MinEdge.X = p.X;
		if(p.Y < MinEdge.Y) MinEdge.Y = p.Y;
		if(p.Z < MinEdge.Z) MinEdge.Z = p.Z;
		if(p.X > MaxEdge.X) MaxEdge.X = p.X;
		if(p.Y > MaxEdge.Y) MaxEdge.Y = p.Y;
		if(p.Z > MaxEdge.Z) MaxEdge.Z = p.Z;
		cacheExtent();
	}

	// Pad with d nodes
	void pad(const v3s16 &d)
	{
		MinEdge -= d;
		MaxEdge += d;
	}

	/*
		const methods
	*/

	const v3s16 &getExtent() const
	{
		return m_cache_extent;
	}

	/* Because MaxEdge and MinEdge are included in the voxel area an empty extent
	 * is not represented by (0, 0, 0), but instead (-1, -1, -1)
	 */
	bool hasEmptyExtent() const
	{
		return MaxEdge - MinEdge == v3s16(-1, -1, -1);
	}

	s32 getVolume() const
	{
		return (s32)m_cache_extent.X * (s32)m_cache_extent.Y * (s32)m_cache_extent.Z;
	}

	bool contains(const VoxelArea &a) const
	{
		// No area contains an empty area
		// NOTE: Algorithms depend on this, so do not change.
		if(a.hasEmptyExtent())
			return false;

		return(
			a.MinEdge.X >= MinEdge.X && a.MaxEdge.X <= MaxEdge.X &&
			a.MinEdge.Y >= MinEdge.Y && a.MaxEdge.Y <= MaxEdge.Y &&
			a.MinEdge.Z >= MinEdge.Z && a.MaxEdge.Z <= MaxEdge.Z
		);
	}
	bool contains(v3s16 p) const
	{
		return(
			p.X >= MinEdge.X && p.X <= MaxEdge.X &&
			p.Y >= MinEdge.Y && p.Y <= MaxEdge.Y &&
			p.Z >= MinEdge.Z && p.Z <= MaxEdge.Z
		);
	}
	bool contains(s32 i) const
	{
		return (i >= 0 && i < getVolume());
	}
	bool operator==(const VoxelArea &other) const
	{
		return (MinEdge == other.MinEdge
				&& MaxEdge == other.MaxEdge);
	}

	VoxelArea operator+(const v3s16 &off) const
	{
		return {MinEdge+off, MaxEdge+off};
	}

	VoxelArea operator-(const v3s16 &off) const
	{
		return {MinEdge-off, MaxEdge-off};
	}

	/*
		Returns 0-6 non-overlapping areas that can be added to
		a to make up this area.

		a: area inside *this
	*/
	void diff(const VoxelArea &a, std::list<VoxelArea> &result)
	{
		/*
			This can result in a maximum of 6 areas
		*/

		// If a is an empty area, return the current area as a whole
		if(a.getExtent() == v3s16(0,0,0))
		{
			VoxelArea b = *this;
			if(b.getVolume() != 0)
				result.push_back(b);
			return;
		}

		assert(contains(a));	// pre-condition

		// Take back area, XY inclusive
		{
			v3s16 min(MinEdge.X, MinEdge.Y, a.MaxEdge.Z+1);
			v3s16 max(MaxEdge.X, MaxEdge.Y, MaxEdge.Z);
			VoxelArea b(min, max);
			if(b.getVolume() != 0)
				result.push_back(b);
		}

		// Take front area, XY inclusive
		{
			v3s16 min(MinEdge.X, MinEdge.Y, MinEdge.Z);
			v3s16 max(MaxEdge.X, MaxEdge.Y, a.MinEdge.Z-1);
			VoxelArea b(min, max);
			if(b.getVolume() != 0)
				result.push_back(b);
		}

		// Take top area, X inclusive
		{
			v3s16 min(MinEdge.X, a.MaxEdge.Y+1, a.MinEdge.Z);
			v3s16 max(MaxEdge.X, MaxEdge.Y, a.MaxEdge.Z);
			VoxelArea b(min, max);
			if(b.getVolume() != 0)
				result.push_back(b);
		}

		// Take bottom area, X inclusive
		{
			v3s16 min(MinEdge.X, MinEdge.Y, a.MinEdge.Z);
			v3s16 max(MaxEdge.X, a.MinEdge.Y-1, a.MaxEdge.Z);
			VoxelArea b(min, max);
			if(b.getVolume() != 0)
				result.push_back(b);
		}

		// Take left area, non-inclusive
		{
			v3s16 min(MinEdge.X, a.MinEdge.Y, a.MinEdge.Z);
			v3s16 max(a.MinEdge.X-1, a.MaxEdge.Y, a.MaxEdge.Z);
			VoxelArea b(min, max);
			if(b.getVolume() != 0)
				result.push_back(b);
		}

		// Take right area, non-inclusive
		{
			v3s16 min(a.MaxEdge.X+1, a.MinEdge.Y, a.MinEdge.Z);
			v3s16 max(MaxEdge.X, a.MaxEdge.Y, a.MaxEdge.Z);
			VoxelArea b(min, max);
			if(b.getVolume() != 0)
				result.push_back(b);
		}

	}

	/*
		Translates position from virtual coordinates to array index
	*/
	s32 index(s16 x, s16 y, s16 z) const
	{
		s32 i = (s32)(z - MinEdge.Z) * m_cache_extent.Y * m_cache_extent.X
			+ (y - MinEdge.Y) * m_cache_extent.X
			+ (x - MinEdge.X);
		return i;
	}
	s32 index(v3s16 p) const
	{