Permalink
Browse files

Parlament

  • Loading branch information...
uwe committed Aug 11, 2011
1 parent 628ca44 commit b74c33c889387591473a462548b62dd386fedb8e
Showing with 91 additions and 1 deletion.
  1. +84 −0 lib/Mittag/Place/Parlament.pm
  2. +7 −1 lib/Mittag/Places.pm
@@ -0,0 +1,84 @@
+package Mittag::Place::Parlament;
+
+use utf8;
+use strict;
+use warnings;
+
+use base qw/Mittag::Place/;
+
+
+sub id { 17 }
+sub url { 'http://www.parlament-hamburg.de/pdf/Mittagskarte.pdf' }
+sub file { 'parlament.txt' }
+sub name { 'Parlament' }
+sub type { 'web' }
+sub address { 'Rathausmarkt 1, 20095 Hamburg' }
+sub geocode { [53.55074, 9.99206] }
+
+
+sub download {
+ my ($self, $downloader) = @_;
+
+ my $file = $self->file;
+ $file =~ s/\.txt$/.html/;
+ $downloader->get_store($self->url, $file);
+
+ my $txt = $downloader->pdf2txt($file, 1);
+ $downloader->store($txt, $self->file);
+}
+
+sub extract {
+ my ($self, $data, $importer) = @_;
+
+ my @data = $self->_trim_split($data);
+
+ my ($day, $month) = $self->_find(qr/Montag, (\d\d)\. ([^ ]+) bis Samstag, /, \@data);
+
+ ###TODO### year
+ my $year = 2011;
+ my $date = DateTime->new(
+ day => $day,
+ month => $self->_from_month($month),
+ year => $year,
+ );
+
+ shift @data;
+
+ my $meal = '';
+ my $price = 0;
+ while (my $line = shift @data) {
+ if ($line =~ /Wählen Sie ein 0,2 l Softgetränk für/) {
+ $importer->save_weekly(
+ id => $self->id,
+ week => $date->ymd('-'),
+ meal => $meal,
+ price => $price,
+ );
+ last;
+ }
+
+ if ($line =~ s/(\d+,\d\d) (?:€|EUR)//) {
+ my $new_price = $1;
+ $new_price =~ s/,/./;
+
+ # save previous meal
+ if ($meal) {
+ $importer->save_weekly(
+ id => $self->id,
+ week => $date->ymd('-'),
+ meal => $meal,
+ price => $price,
+ );
+ }
+
+ $price = $new_price;
+ $meal = $self->_trim($line);
+ }
+ else {
+ $meal .= ' ' . $line;
+ }
+ }
+}
+
+
+1;
View
@@ -9,7 +9,13 @@ use Module::Find qw/useall/;
my @places = useall 'Mittag::Place';
-my %place = map { $_->id => $_->new } @places;
+my %place = ();
+foreach my $place (@places) {
+ my $id = $place->id;
+ # 12: Paparazzi and Pararazzi2
+ die "ID $id used twice: $place{$id}" if $place{$id} and $id != 12;
+ $place{$id} = $place;
+}
sub place_by_id {

0 comments on commit b74c33c

Please sign in to comment.