aboutsummaryrefslogtreecommitdiff
path: root/mensa/backends/satyam.py
diff options
context:
space:
mode:
Diffstat (limited to 'mensa/backends/satyam.py')
-rw-r--r--mensa/backends/satyam.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/mensa/backends/satyam.py b/mensa/backends/satyam.py
new file mode 100644
index 0000000..7ac53a0
--- /dev/null
+++ b/mensa/backends/satyam.py
@@ -0,0 +1,38 @@
+import urllib.request, urllib.error, urllib.parse
+from lxml import etree
+from lxml.cssselect import CSSSelector
+import html5lib
+from mensa.base import *
+import re
+import sys
+from yapsy.IPlugin import IPlugin
+
+class Satyam(IPlugin):
+ def register_restaurants(self) :
+ r = Restaurant("Satyam", "Satyam", self, "dummy")
+ register_restaurant(r)
+ def get_food_items(self, **kwargs) :
+ s = sys.stderr
+ sys.stderr = open("/dev/null", "w")
+ user_agent = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64)'
+ headers = {'User-Agent': user_agent}
+
+ req = urllib.request.Request('http://www.mysatyam.de/angebote/express-mittagstisch.html', headers=headers)
+ response = urllib.request.urlopen(req)
+ the_page = response.read()
+ document = html5lib.parse(the_page, treebuilder="lxml")
+ groupsel = CSSSelector('.news-latest-item-content')
+ k = etree.tostring(groupsel(document)[0])
+ name = re.sub(r'<.+?>', ' ', str(k))
+ name = etree.fromstring("<p>%s</p>"%name).text.strip()
+ name = name.replace("\\n", "")
+ name = " ".join(name.split())
+
+ name = name.replace("5,95 €", "")
+ sys.stderr = s
+ return [Food("Mittagstisch Express", "5,95 €", "Mittagstisch", 2, name[3:-1])]
+
+
+# if __name__ == "__main__":
+# food = get_food_items()
+# print(formt(food))