Skip to content

Commit

Permalink
Useful programs
Browse files Browse the repository at this point in the history
  • Loading branch information
davorg committed Dec 4, 2016
1 parent 18f245c commit 1560e7f
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
30 changes: 30 additions & 0 deletions get_succ
@@ -0,0 +1,30 @@
#!/usr/bin/perl

use strict;
use warnings;
use 5.010;

use Succession::Schema;
use DateTime;
use DateTime::Format::Strptime;

my $date = shift;

if (defined $date) {
$date = DateTime::Format::Strptime->new(
pattern => '%Y-%m-%d',
)->parse_datetime($date);
} else {
$date = DateTime->now;
}

my $sch = Succession::Schema->get_schema;

my ($sov) = $sch->resultset('Sovereign')->sovereign_on_date($date);

say 'Sovereign on ', $date->strftime('%d %B %Y'), ': ', $sov->name;

say 'Succession:';

my $i = 1;
say $i++, ': ', $_->name for $sov->succession_on_date($date);
42 changes: 42 additions & 0 deletions load
@@ -0,0 +1,42 @@
#!/usr/bin/perl

use strict;
use warnings;
use 5.010;

use Text::ParseWords;
use DateTime::Format::Strptime;
use Succession::Schema;

my $dt_p = DateTime::Format::Strptime->new(
pattern => '%d/%m/%Y',
);

my $sch = Succession::Schema->get_schema;

my $person_rs = $sch->resultset('Person');

<>;

my @cols = qw[name born died parent family_order];

my %people;

while (<>) {
chomp;
my %rec;
@rec{@cols} = map { length ? $_ : undef} parse_line(',', 0, $_);

$rec{born} = $dt_p->parse_datetime($rec{born});
$rec{died} = $dt_p->parse_datetime($rec{died}) if $rec{died};

if ($rec{parent}) {
if (exists $people{$rec{parent}}) {
$rec{parent} = $people{$rec{parent}}->id;
} else {
warn "Can't find parent for $rec{name} ($rec{parent})\n";
next;
}
}
$people{$rec{name}} = $person_rs->create(\%rec);
}

0 comments on commit 1560e7f

Please sign in to comment.