<commit_before>#
# InfoServant - Your information, delivered.
# Copyright (C) 2013 <NAME>
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

package InfoServant::Dashboard;

use Mojo::Base 'Mojolicious::Controller';

use SiteCode::Account;
use SiteCode::Feed;
use SiteCode::Feeds;
use SiteCode::DBX;

use Mojo::Util;

use HTML::Entities;
use Regexp::Common qw(URI);
use XML::OPML::LibXML;
use File::Temp;
use Time::Local;

sub dateify {
    if ($_[0] =~ m/^(\d+)-(\d+)-(\d+)\s+(\d+).(\d+)/) {
        my $dt = DateTime->new(
            year => $1,
            month => $2,
            day => $3,
            hour => $4,
            minute => $5,
        );

        return($dt);
    }
    else {
        return(DateTime->now());
    }
}

sub show {
    my $self = shift;

    if (!$self->session("account_id")) {
        my $url = $self->url_for('/');
        return($self->redirect_to($url));
    }

    my $account = undef;

    eval {
        $account = SiteCode::Account->new(id => $self->session("account_id"));
    };
    if ($@) {
        $self->app->log->debug("InfoServant::Dashboard::show: $@");
        $self->session(expires => 1);

        my $url = $self->url_for('/');
        return($self->redirect_to($url));
    }

    $self->stash(account_verified => $account->verified());

    my $have_feeds = SiteCode::Feeds->haveFeeds(account => $account);
    $self->stash(have_feeds => $have_feeds);

    # If the user selects all feeds
    if ($self->param("feed")) {
        if (-1 == $self->param("feed")) {
            delete $self->session->{cur_feed};
        }
        else {
            $self->session(cur_feed => $self->param("feed"));
       }
    }
    my @entries = ();
    my $feeds = SiteCode::Feeds->new(account => $account);
    foreach my $l (@{ $feeds->latest(limit => 30, offset => $self->param("offset") || 0, feed => $self->session("cur_feed")) }) {
        my $obj = SiteCode::Feed->new(id => $$l{feed_id}, route => $self);
        my $entry = $obj->entry($$l{entry_id}, $account->id());

        my $dt = dateify($$entry{issued});
        my $date = $dt->strftime("%A, %B, %e, %Y");
        my $time = $dt->strftime("%H:%M");
        my $the_m = $dt->strftime("%p");

        my %html = ();
        if ($self->session("cur_feed")) {
            my $html = $obj->html(entry_id => $$l{entry_id}, account_id => $account->id);
            # $html{html} = $html; # substr($html, 0, 256);
        }

        push(@entries, { %html, id => $$entry{id}, date => $date, time => $time, the_m => $the_m, feed_title => $$entry{feed_title}, entry_id => $$l{entry_id}, issued => $$entry{issued}, title => $$entry{title}, feed_id => $obj->id() });
    }
    if (scalar @entries) {
        $self->stash(have_entries => 1);
    }

    my @feeds = ();
    foreach my $f (@{ $feeds->feeds() }) {
        push(@feeds, { id => $$f{id}, name => $$f{name}});
    }
    if (@feeds) {
        $self->stash(have_feeds => 1);
    }

    $self->app->log->debug("InfoServant::Dashboard::show:" . __LINE__);
    if ($self->session("cur_feed")) {
        $self->app->log->debug("InfoServant::Dashboard::show:" . __LINE__);
        my $feed = SiteCode::Feed->new(id => $self->session("cur_feed"), route => $self);
        my $feed_title = $feed->key("title") || $feed->key("url");
        $self->stash(cur_title => $feed_title);
    }

    $self->stash(offset => $self->param("offset")) if $self->param("offset");

    $self->render(entries => \@entries, feeds => \@feeds);
}

sub details {
    my $self = shift;<commit_msg>Dead code<commit_after>#
# InfoServant - Your information, delivered.
# Copyright (C) 2013 <NAME>
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

package InfoServant::Dashboard;

use Mojo::Base 'Mojolicious::Controller';

use SiteCode::Account;
use SiteCode::Feed;
use SiteCode::Feeds;
use SiteCode::DBX;

use Mojo::Util;

use HTML::Entities;
use Regexp::Common qw(URI);
use XML::OPML::LibXML;
use File::Temp;
use Time::Local;

sub dateify {
    if ($_[0] =~ m/^(\d+)-(\d+)-(\d+)\s+(\d+).(\d+)/) {
        my $dt = DateTime->new(
            year => $1,
            month => $2,
            day => $3,
            hour => $4,
            minute => $5,
        );

        return($dt);
    }
    else {
        return(DateTime->now());
    }
}

sub show {
    my $self = shift;

    if (!$self->session("account_id")) {
        my $url = $self->url_for('/');
        return($self->redirect_to($url));
    }

    my $account = undef;

    eval {
        $account = SiteCode::Account->new(id => $self->session("account_id"));
    };
    if ($@) {
        $self->app->log->debug("InfoServant::Dashboard::show: $@");
        $self->session(expires => 1);

        my $url = $self->url_for('/');
        return($self->redirect_to($url));
    }

    $self->stash(account_verified => $account->verified());

    my $have_feeds = SiteCode::Feeds->haveFeeds(account => $account);
    $self->stash(have_feeds => $have_feeds);

    # If the user selects all feeds
    if ($self->param("feed")) {
        if (-1 == $self->param("feed")) {
            delete $self->session->{cur_feed};
        }
        else {
            $self->session(cur_feed => $self->param("feed"));
       }
    }
    my @entries = ();
    my $feeds = SiteCode::Feeds->new(account => $account);
    foreach my $l (@{ $feeds->latest(limit => 30, offset => $self->param("offset") || 0, feed => $self->session("cur_feed")) }) {
        my $obj = SiteCode::Feed->new(id => $$l{feed_id}, route => $self);
        my $entry = $obj->entry($$l{entry_id}, $account->id());

        my $dt = dateify($$entry{issued});
        my $date = $dt->strftime("%A, %B, %e, %Y");
        my $time = $dt->strftime("%H:%M");
        my $the_m = $dt->strftime("%p");

        push(@entries, { id => $$entry{id}, date => $date, time => $time, the_m => $the_m, feed_title => $$entry{feed_title}, entry_id => $$l{entry_id}, issued => $$entry{issued}, title => $$entry{title}, feed_id => $obj->id() });
    }
    if (scalar @entries) {
        $self->stash(have_entries => 1);
    }

    my @feeds = ();
    foreach my $f (@{ $feeds->feeds() }) {
        push(@feeds, { id => $$f{id}, name => $$f{name}});
    }
    if (@feeds) {
        $self->stash(have_feeds => 1);
    }

    $self->app->log->debug("InfoServant::Dashboard::show:" . __LINE__);
    if ($self->session("cur_feed")) {
        $self->app->log->debug("InfoServant::Dashboard::show:" . __LINE__);
        my $feed = SiteCode::Feed->new(id => $self->session("cur_feed"), route => $self);
        my $feed_title = $feed->key("title") || $feed->key("url");
        $self->stash(cur_title => $feed_title);
    }

    $self->stash(offset => $self->param("offset")) if $self->param("offset");

    $self->render(entries => \@entries, feeds => \@feeds);
}

sub details {
    my $self = shift;
{'fraction_non_alphanumeric': 0.19962663347853143, 'fraction_numerical': 0.004978220286247666, 'mean_word_length': 2.8376313276026743, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 190, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4620182', 'n_tokens_mistral': 2723, 'n_tokens_neox': 2660, 'n_words': 654}