]> www.fi.muni.cz Git - aoc.git/commitdiff
Infrastructure cleanups
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Wed, 21 Dec 2022 08:07:56 +0000 (09:07 +0100)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Wed, 21 Dec 2022 08:07:56 +0000 (09:07 +0100)
.gitignore
RESOURCES.otl [new file with mode: 0644]
get [moved from 2022/get with 98% similarity]
leaderboard [moved from 2021/leaderboard with 57% similarity]
lib/Y/AoC.pm

index 68be32c53d72c406e028d454b897f3021b32b23c..ab993456df753e6947d0daabfe2c0c0adf8fe7fa 100644 (file)
@@ -1,7 +1,5 @@
 .*.swp
 *.txt
-cache-*.json
-cookie
-id.txt
+cache
 a.out
-leaderboard
+*/backup
diff --git a/RESOURCES.otl b/RESOURCES.otl
new file mode 100644 (file)
index 0000000..8da38bd
--- /dev/null
@@ -0,0 +1,17 @@
+Eric Wastl's talk
+       https://www.youtube.com/watch?v=gibVyxpi-qA
+
+mcpowers' tips
+       https://gist.github.com/mcpower/87427528b9ba5cac6f0c679370789661
+
+epsalon's Perl repo
+       https://github.com/epsalon/advent_of_code
+
+betaveros' howto
+       https://blog.vero.site/post/advent-leaderboard
+       https://www.youtube.com/watch?v=jls4zhEhlog
+
+Vim:
+       increment a visual block
+       visual-block <number> g Ctrl-A (or Ctrl-X decrements)
+
diff --git a/2022/get b/get
similarity index 98%
rename from 2022/get
rename to get
index 760e024c69248e9284bd98b2a4ac16b04c2f2290..13a39df2bfc7fef0fe516323a233ff9fd38c576c 100755 (executable)
--- a/2022/get
+++ b/get
@@ -3,7 +3,7 @@
 use v5.36;
 use strict;
 
-use Y::AoC qw(grey);
+use Y::AoC qw(grey red);
 use Y::AoC::UA;
 
 use Mojo::UserAgent -signatures;
similarity index 57%
rename from 2021/leaderboard
rename to leaderboard
index 42874cdcb4b3d6150b9445663d1b9c5f634881ff..3f1e7ba898a1499e797e859fd7a6c26d404764ea 100755 (executable)
@@ -1,45 +1,44 @@
 #!/usr/bin/perl -w
 
-use v5.16;
-use Mojo::UserAgent -signatures;
+use v5.36;
+use Y::AoC::UA;
+use Y::AoC;
 use Mojo::JSON qw(from_json);
-use Mojo::File qw(curfile);
 use Mojo::Util qw(getopt dumper);
 use POSIX;
+use Time::Local;
 
 my $board_id = 652041;
 my $my_name = 'Yenya';
 my $day = (localtime(time))[3];
+my $year = Y::AoC::year;
 my $mode = 'r';
 my $force;
 getopt
        'n|name=s'      => \$my_name,
        'd|day=i'       => \$day,
+       'y|year=i'      => \$year,
        '1|first-task'  => sub { $mode = '1' },
        '2|second-task' => sub { $mode = '2' },
        'r|relative'    => sub { $mode = 'r' },
        'b|board=i'     => \$board_id,
        'f|force'       => \$force
 or die "Usage: $0 [-n username] [-1|-2|-r] [-b board_id]\n";
-my $cache_filename = "cache-$board_id.json";
-my $cached = curfile->sibling($cache_filename);
 
-if ($force || !$cached->stat || time - $cached->stat->mtime > 900) {
-       warn "Downloading $cache_filename\n";
-       chomp(my $cookie = curfile->sibling('cookie')->slurp);
-       my $res = Mojo::UserAgent->new->get(
-               "https://adventofcode.com/2021/leaderboard/private/view/$board_id.json",
-               { Cookie => $cookie }
-       )->result;
-
-       $cached->spurt($res->body);
-}
-
-my $json = from_json $cached->slurp;
+my $res = Y::AoC::UA::request(
+       "https://adventofcode.com/$year/leaderboard/private/view/$board_id.json",
+       {
+               max_age  => $force ? 0 : 900,
+               body     => 1,
+               cache_to => "board-$board_id-$year.json",
+       },
+);
 
+my $json = from_json($res);
 
 my %times;
 my $my_time;
+my $min_time;
 for my $name (keys %{ $json->{members} }) {
         my $member = $json->{members}->{$name};
        my $level = $member->{completion_day_level}->{$day}
@@ -57,11 +56,32 @@ for my $name (keys %{ $json->{members} }) {
        }
        my $id_or_name = $member->{name} // 'Anonymous user #' . $member->{id};
        $times{ $id_or_name } = $time;
+       $min_time = $level->{1}->{get_star_ts}
+               if !defined $min_time || $min_time > $level->{1}->{get_star_ts};
        $my_time = $time
                if $id_or_name eq $my_name;
 }
 
+my @localtime = localtime($min_time);
+$localtime[0] = 0;
+$localtime[1] = 0;
+$localtime[2] = 6;
+my $start = timelocal(@localtime);
+say "Start at ", POSIX::strftime("%Y-%m-%d %H:%M:%S",  @localtime);
+
 for my $name (sort { $times{$a} <=> $times{$b} } keys %times) {
        $my_time //= $times{$name};
-       printf("%6d %6d %s\n", $times{$name}, $times{$name} - $my_time, $name);
+       if ($mode eq 'r') {
+               printf("%9d %s\n",
+                       $times{$name} - $my_time,
+                       $name,
+               );
+       } else {
+               printf("%19.19s %9d %9d %s\n",
+                       POSIX::strftime("%Y-%m-%d %H:%M:%S", localtime($times{$name})),
+                       $times{$name}-$start,
+                       $times{$name} - $my_time,
+                       $name,
+               );
+       }
 }
index 8fbb606a6486cba86f744dd9af0332441b61e6de..31b4532694b97a840f63e4fe9ce9a07e1847d8e2 100644 (file)
@@ -7,6 +7,7 @@ our @EXPORT_OK = qw(red grey white yellow day year);
 
 use FindBin qw($Bin);
 use Term::ANSIColor;
+use Cwd;
 
 sub red    { colored(['bright_red    on_black'], @_); }
 sub white  { colored(['bright_white  on_black'], @_); }
@@ -20,6 +21,9 @@ sub day {
 
 sub year {
        my ($num) = $Bin =~ /.*(\d{4})/;
+       if (!defined $num) {
+               ($num) = getcwd =~ /.*(\d{4})/;
+       }
        $num;
 }