aboutsummaryrefslogtreecommitdiff
path: root/mensa/backends/satyam.py
blob: e01b546f7c1a4946628b9f1aaae74d09b6709327 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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")
        sys.stderr = s
        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 €", "")

        return [Food("Mittagstisch Express", "5,95 €", "Mittagstisch", 2, name[3:-1])]
    

# if __name__ == "__main__":
#     food = get_food_items()
#     print(formt(food))