about summary refs log tree commit diff stats
path: root/ara.pl
diff options
context:
space:
mode:
Diffstat (limited to 'ara.pl')
-rwxr-xr-xara.pl93
1 files changed, 47 insertions, 46 deletions
diff --git a/ara.pl b/ara.pl
index f522d72..1c28fe9 100755
--- a/ara.pl
+++ b/ara.pl
@@ -13,8 +13,8 @@ use OpenBSD::Unveil;
 
 # Unveil @INC.
 foreach my $path (@INC) {
-    unveil( $path, 'rx' ) or
-        die "Unable to unveil: $!";
+    unveil( $path, 'rx' )
+        or die "Unable to unveil: $!";
 }
 
 my ( $use_local_file, $get_latest, $state_notes, $rows_to_print );
@@ -25,8 +25,7 @@ GetOptions(
     "notes" => \$state_notes,
     "rows=i" => \$rows_to_print,
     "help" => sub { HelpMessage() },
-    ) or
-    die "Error in command line arguments";
+) or die "Error in command line arguments";
 
 sub HelpMessage {
     print "Options:
@@ -39,8 +38,8 @@ sub HelpMessage {
     exit;
 }
 
-die "Can't use --local and --latest together\n" if
-    ( $use_local_file and $get_latest );
+die "Can't use --local and --latest together\n"
+    if $use_local_file and $get_latest ;
 
 # %unveil contains list of paths to unveil with their permissions.
 my %unveil = (
@@ -49,15 +48,15 @@ my %unveil = (
     "/home" => "", # Veil "/home", we don't want to read it.
     "/tmp" => "rwc",
     "/dev/null" => "rw",
-    );
+);
 
 # Unveil each path from %unveil.
 keys %unveil;
 
 # We use sort because otherwise keys is random order everytime.
 foreach my $path ( sort keys %unveil ) {
-    unveil( $path, $unveil{$path} ) or
-        die "Unable to unveil: $!";
+    unveil( $path, $unveil{$path} )
+        or die "Unable to unveil: $!";
 }
 
 my $file = '/tmp/data.json';
@@ -68,16 +67,15 @@ if ( -e $file ) {
     my $file_stat = path($file)->stat;
     $file_mtime = Time::Moment->from_epoch( $file_stat->[9] );
 } else {
-    warn "File '$file' doesn't exist\nFetching latest...\n" if
-        $use_local_file;
+    warn "File '$file' doesn't exist\nFetching latest...\n"
+        if $use_local_file;
 }
 
 # Fetch latest data only if the local data is older than 8 minutes or
 # if the file doesn't exist.
-if ( ( not -e $file ) or
-     ( $file_mtime <
-       Time::Moment->now_utc->minus_minutes(8) ) or
-     $get_latest ) {
+if ( not -e $file
+         or $file_mtime < Time::Moment->now_utc->minus_minutes(8)
+         or $get_latest ) {
     require File::Fetch;
 
     # Fetch latest data from api.
@@ -85,16 +83,16 @@ if ( ( not -e $file ) or
     my $ff = File::Fetch->new(uri => $url);
 
     # Save the api response under /tmp.
-    $file = $ff->fetch( to => '/tmp' ) or
-        die $ff->error;
+    $file = $ff->fetch( to => '/tmp' )
+        or die $ff->error;
 }
 
 # Slurp api response to $file_data.
 my $file_data = path($file)->slurp;
 
 # Block further unveil calls.
-unveil() or
-    die "Unable to lock unveil: $!";
+unveil()
+    or die "Unable to lock unveil: $!";
 
 # Decode $file_data to $json_data.
 my $json_data = decode_json($file_data);
@@ -113,18 +111,21 @@ if ( $state_notes ) {
     @months = qw( lol Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
 
     $covid_19_data = Text::ASCIITable->new();
-    $covid_19_data->setCols( 'State',
-                             'Confirmed',
-                             'Active',
-                             'Recovered',
-                             'Deaths',
-                             'Last Updated',
-        );
+    $covid_19_data->setCols(
+        'State',
+        'Confirmed',
+        'Active',
+        'Recovered',
+        'Deaths',
+        'Last Updated',
+    );
+
+    $covid_19_data->alignCol( {
+        'Confirmed' => 'left',
+        'Recovered' => 'left',
+        'Deaths' => 'left',
+    } );
 
-    $covid_19_data->alignCol( { 'Confirmed' => 'left',
-                                    'Recovered' => 'left',
-                                    'Deaths' => 'left',
-                              } );
     $today = Time::Moment
         ->now_utc
         ->plus_hours(5)
@@ -133,38 +134,38 @@ if ( $state_notes ) {
 
 # Print all the rows if $rows_to_print evaluates to False or is
 # greater than the size of @$statewise or if user wants $state_notes.
-$rows_to_print = scalar @$statewise if
-    ( ( not $rows_to_print ) or
-      ( $rows_to_print > scalar @$statewise ) or
-      $state_notes );
+$rows_to_print = scalar @$statewise
+    if ( not $rows_to_print
+             or $rows_to_print > scalar @$statewise
+             or $state_notes );
 
 foreach my $i ( 0 ... $rows_to_print - 1  ) {
     my $state = $statewise->[$i]{state};
-    $state = "India" if
-        $state eq "Total";
+    $state = "India"
+        if $state eq "Total";
 
-    $state = $statewise->[$i]{statecode} if
-        length($state) > 16;
+    $state = $statewise->[$i]{statecode}
+        if length($state) > 16;
 
     if ( $state_notes ) {
         $notes_table->addRow(
             $state,
             $statewise->[$i]{statenotes},
-            ) unless
-            length($statewise->[$i]{statenotes}) == 0;
+        ) unless length($statewise->[$i]{statenotes}) == 0;
     } else {
         my $update_info;
         my $lastupdatedtime = $statewise->[$i]{lastupdatedtime};
         my $last_update_dmy = substr( $lastupdatedtime, 0, 10 );
 
         # Add $update_info.
-        if ( $last_update_dmy eq $today->strftime( "%d/%m/%Y" ) ) {
+        if ( $last_update_dmy
+                 eq $today->strftime( "%d/%m/%Y" ) ) {
             $update_info = "Today";
-        } elsif ( $last_update_dmy eq
-                  $today->minus_days(1)->strftime( "%d/%m/%Y" ) ) {
+        } elsif ( $last_update_dmy
+                      eq $today->minus_days(1)->strftime( "%d/%m/%Y" ) ) {
             $update_info = "Yesterday";
-        } elsif ( $last_update_dmy eq
-                  $today->plus_days(1)->strftime( "%d/%m/%Y" ) ) {
+        } elsif ( $last_update_dmy
+                      eq $today->plus_days(1)->strftime( "%d/%m/%Y" ) ) {
             $update_info = "Tomorrow"; # Hopefully we don't see this.
         } else {
             $update_info =
@@ -191,7 +192,7 @@ foreach my $i ( 0 ... $rows_to_print - 1  ) {
             $recovered,
             $deaths,
             $update_info,
-            );
+        );
     }
 }
 
'>393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636