I often check what our canteen offer for lunch before we leave our building. The website that presents this portfolio is one of the worst I’ve ever seen and meanwhile I noticed that my private walking Mensa planer has still some bugs, so I had to think about an alternative solution and developed a little Perl script…

My initial idea was to read the website, parse the XML code and print the meals. Not a bit of it! The code of this site is nothing like valid! They invent new tags I’ve never heard about, they close nowhere opened paragraphs or table cells, I do not find the html-closing tag (the document ends with closing it’s body) and so on… It’s to much to mention all it’s unique features, but let me blame the producer: Peinhardt IT Systeme. Seems to be professionals… (A notice has left my mailbox, looking forward to their answer)

How ever, XML parsing fails, solving the bugs also fails, to much of it… So I’m now just grabbing the HTML-code, to extract the interesting content, with a more or less ugly regex, and print them to console… Here is the code:

#!/usr/bin/perl -w

use warnings;
use strict;
use LWP::UserAgent;

binmode STDOUT, ":utf8";

my $url = "http://meine-mensa.de/speiseplan_iframe";
my $mensa = 5;

my $browser = LWP::UserAgent->new(parse_head => 0);
$browser->timeout(10);

my $response = $browser->post ($url, ["selected_locations[]" => $mensa]);
my $content = $response->decoded_content ();
$content =~ s/\n//g;

while ($content =~ /<span style="font-weight: normal; font-size: 12px" class="counter_name">(.+?)<\/span>.+?<span.+?>(.+?)<\//gi)
{
	print $1.":\t".$2."\n";
}

So if somebody is also joining the Mensa Weinberg, you can copy this code or download it. The other canteens are also available, just change the value of the variable $mensa to your preferred one. The numbers can be found in the source code of this stupid website. Ok, to save you from trouble here are the numbers:

Cafeteria Brandbergweg
11
Cafeteria Burg
12
Mensa Bernburg
8
Mensa Dessau
13
Mensa Franckesche Stiftungen
14
Mensa Harz
3
Mensa Köthen
7
Mensa Neuwerk
9
Mensa Tulpe
10
Mensa Weinberg
5

Well, that’s it! Now you can decide within seconds whether it’s worthy to go to lunch or better stay hungry ;)

Download: Perl: essen.pl (Please take a look at the man-page. Browse bugs and feature requests.)

Martin Scharm

stuff. just for the records.

Do you like this page?
You can actively support me!

Leave a comment

There are multiple options to leave a comment: