From 952fec8cc54b6f5afdb9038b182d671eed8fe088 Mon Sep 17 00:00:00 2001 From: Andinus Date: Sat, 29 Aug 2020 22:59:35 +0530 Subject: Add timeline command After this I'll make it possible to call single user timeline, like `pyxis timeline '. We will check in early in code & read only this file. Also, need to append user information in `%twtxt' along with support for multiple entries in single date. Currently only one entry will show up if there is a date clash. I'll fix these by changing the data structure to hash table of a list of hash table. So the list will contain 2 hashes - user & entry & the list of this will be store in hash table so as to not over write multiple entries of same time. --- pyxis.pl | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/pyxis.pl b/pyxis.pl index 6232515..a0e4cba 100755 --- a/pyxis.pl +++ b/pyxis.pl @@ -6,6 +6,7 @@ use feature 'say'; use Path::Tiny; use Getopt::Long; +use Term::ANSIColor qw/:pushpop/; my %options; GetOptions( @@ -59,7 +60,40 @@ my %dispatch = ( my $res = $http->mirror($url, $file); $res->{success} ? do {say "$feed updated" if $options{verbose}} - : warn "failed to fetch $feed - $url\n" + : warn "failed to fetch $feed - $url\n$!\n" + } + }, + timeline => sub { + my %twtxt; + for my $feed (path($feeds_dir)->children) { + for my $line ($feed->lines) { + chomp $line; + next if (substr($line, 0, 1) eq "#" + or length $line == 0); + my @tmp = split /\t/, $line; + + # Get $date & $entry from @tmp. This can over-write + # entries if they were posted at same time, very + # unlikely but possible. + my $date = shift @tmp; + my $entry = join '', @tmp; + $twtxt{$date} = $entry; + } + } + require Time::Moment; + + my %epoch_twtxt; + foreach my $date (sort keys %twtxt) { + my $tm = Time::Moment->from_string($date); + my $epoch = $tm->epoch; + $epoch_twtxt{$epoch} = $twtxt{$date}; + } + + foreach my $epoch (reverse sort keys %epoch_twtxt) { + my $tm = Time::Moment->from_epoch($epoch); + my $date = LOCALCOLOR MAGENTA $tm->strftime(q{%b %d }); + $date .= LOCALCOLOR GREEN $tm->strftime(q{%H:%M}); + say "$date $epoch_twtxt{$epoch}"; } }, ); -- cgit 1.4.1-2-gfad0