#!/usr/bin/perl

use strict;
use warnings;

use Data::Dumper;
use List::Util qw(shuffle);

use Ernad::Learn;
use Ernad::Notify;

## make sure we can run this from the web interface
use lib '/home/ernad/ernad/perl';

my $impna = $ARGV[0] // die "no impna";
my $notify= $ARGV[1] // '';
my $l=Ernad::Learn->new({'impna' => $impna,
                         'verbose' => 1});
## required for the email software
our $e=$l->{'e'};
## do all
foreach my $repcode (shuffle $e->list_repcodes()) {
  if($e->{'r'}) {
    $e->{'r'}->load($repcode);
  }
  my $ps_rif=$l->presort_ahead($repcode) or next;
  if($notify) {
    &Ernad::Notify::notify($e,$ps_rif);
  }
  exit;
}
