From 2195b639091842492ea11ab8b91a631c59a7d32f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20P=C3=A9rez-Cerezo?= Date: Wed, 4 Oct 2017 00:42:18 +0200 Subject: Modularized program --- backends/satyam.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 backends/satyam.py (limited to 'backends/satyam.py') diff --git a/backends/satyam.py b/backends/satyam.py new file mode 100644 index 0000000..a20d6bb --- /dev/null +++ b/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 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) : + 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("

%s

"%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)) -- cgit v1.2.3