Permalink
Browse files

fix Gerichtskantine (unregular data)

  • Loading branch information...
1 parent f0588a9 commit cbfddbe99d60b4c7e13348cf10d4161cfa6d2b0e @uwe uwe committed Jul 24, 2011
Showing with 21 additions and 5 deletions.
  1. +7 −0 bin/extract.pl
  2. +13 −4 lib/Mittag/Importer.pm
  3. +1 −1 lib/Mittag/Place/Gerichtskantine.pm
View
@@ -5,6 +5,7 @@
use File::Slurp qw/read_file/;
use FindBin;
+use Getopt::Long;
use Module::Find qw/useall/;
use lib $FindBin::Bin . '/../lib';
@@ -13,10 +14,16 @@
use Mittag::Importer;
+my $debug = 0;
+GetOptions(
+ 'debug|d' => \$debug,
+);
+
my $config = Mittag::Config->new($FindBin::Bin . '/..');
my $schema = Mittag::DB::Schema->connect_with_config($config);
my $importer = Mittag::Importer->new({
config => $config,
+ debug => $debug,
schema => $schema,
});
View
@@ -8,10 +8,11 @@ use warnings;
use base qw/Class::Accessor::Faster/;
use Carp qw/croak/;
+use Data::Dump qw/pp/;
use DateTime;
-__PACKAGE__->mk_ro_accessors(qw/config schema/);
+__PACKAGE__->mk_ro_accessors(qw/config debug schema/);
sub rs {
@@ -30,13 +31,17 @@ sub save_weekly {
my ($from, $to) = __from_to($arg{week});
- return $self->rs('WeeklyOffer')->find_or_create(
+ my %data = (
place_id => $arg{id},
from_date => $from,
to_date => $to,
name => $arg{meal},
price => $arg{price},
);
+
+ warn pp \%data if $self->debug;
+
+ return $self->rs('WeeklyOffer')->find_or_create(%data);
}
sub save {
@@ -46,12 +51,16 @@ sub save {
croak "$_ missing" unless $arg{$_};
}
- return $self->rs('DailyOffer')->find_or_create({
+ my %data = (
place_id => $arg{id},
date => $arg{date},
name => $arg{meal},
price => $arg{price},
- });
+ );
+
+ warn pp \%data if $self->debug;
+
+ return $self->rs('DailyOffer')->find_or_create(%data);
}
sub __from_to {
@@ -115,7 +115,7 @@ sub _meal {
while (@$data) {
my $line = shift @$data;
- if ($line =~ /^(\d,\d\d)$/) {
+ if ($line =~ /^(\d,\d\d)/) {
my $price = $1;
$price =~ s/,/./;
return ($meal, $price);

0 comments on commit cbfddbe

Please sign in to comment.