|).*$', re.DOTALL).match(data)
if not match:
return False
data = match.group(1)
r = re.compile(r'.*?
]*>(.*?)
', re.DOTALL)
r2 = re.compile(r'(?:.*?
]*>(.*?) | ){4}', re.DOTALL)
mealstr = ''
pos = 0
while not r2.match(mealstr):
match = r.match(data, pos)
if not match:
return False
mealstr = match.group(1)
pos = match.end()
match = r.match(data, pos)
if not match:
return False
pricestr = match.group(1)
meals = []
pos = 0
r = re.compile(r'\s*
(.+?) | ', re.DOTALL)
match = r.match(mealstr, pos)
while match:
meals.append(match.group(2))
if len(meals) >= 4:
break
pos = match.end()
match = r.match(mealstr, pos)
if len(meals) < 4:
return False
prices = []
pos = 0
r = re.compile(r'\s*
(.+?) | ', re.DOTALL)
match = r.match(pricestr, pos)
while match:
prices.append(match.group(1))
if len(prices) >= 4:
break
pos = match.end()
match = r.match(pricestr, pos)
if len(prices) < 4:
return False
def unescape(s):
s = s.replace(' ', '')
s = s.replace('€', '€')
s = s.replace('ä', 'ä')
s = s.replace('Ä', 'Ä')
s = s.replace('ö', 'ö')
s = s.replace('Ö', 'Ö')
s = s.replace('ü', 'ü')
s = s.replace('Ü', 'Ü')
s = s.replace('ß', 'ß')
s = s.replace('&', '&')
s = s.replace('<', '<')
s = s.replace('>', '>')
s = s.replace('"', '"')
s = s.replace('“', '“')
s = s.replace('„', '„')
s = s.replace('–', '–')
s = s.replace('
', ' ')
s = re.sub(r'-\s+', '-', s)
s = re.sub(r'\s+', ' ', s)
s = re.sub(r'([a-zäöüß])-([a-zäöüß])', r'\1\2', s)
s = re.sub(r'
![]()
]*logo_bio[^>]*>', 'Bio', s)
s = re.sub(r'<[^>]*>', '', s)
return s
meals = map(unescape, meals)
prices = map(unescape, prices)
reply = 'Mensa-Menü für den %s\n\n' % day.strftime('%d.%m.%y')
if meals[0]:
reply += 'Eintopf: %s (%s)\n' % (meals[0].strip(), prices[0].strip())
if meals[1]:
reply += 'Hauptgericht 1: %s (%s)\n' % (meals[1].strip(), prices[1].strip())
if meals[2]:
reply += 'Hauptgericht 2: %s (%s)\n' % (meals[2].strip(), prices[2].strip())
if meals[3]:
reply += 'Vegetarisches Hauptgericht: %s (%s)\n' % (meals[3].strip(), prices[3].strip())
return reply
reply = handle_data(data)
if not reply:
reply = '%s kein Mensa-Menü... ist vielleicht Wochenende?' % daystr
handler.reply(reply.strip())