about summary refs log tree commit diff stats
path: root/pyxis.pl
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-08-29 22:59:35 +0530
committerAndinus <andinus@nand.sh>2020-08-29 22:59:35 +0530
commit952fec8cc54b6f5afdb9038b182d671eed8fe088 (patch)
tree241685aca3c11a828a622b5278c8100eea0b7ea1 /pyxis.pl
parentf23b9fda2c6659d9b32fec67e0e1ba070f6c70b0 (diff)
downloadpyxis-952fec8cc54b6f5afdb9038b182d671eed8fe088.tar.gz
Add timeline command
After this I'll make it possible to call single user timeline, like
`pyxis timeline <user>'. 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.
Diffstat (limited to 'pyxis.pl')
-rwxr-xr-xpyxis.pl36
1 files changed, 35 insertions, 1 deletions
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}";
         }
     },
 );