diff options
author | Andinus <andinus@nand.sh> | 2020-05-29 17:47:05 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2020-05-29 17:47:05 +0530 |
commit | fbc0e48541b10b743e5376ffe69943ce40a871f5 (patch) | |
tree | e7ae653c5a2f22d597ced049cd0eb7b03a542761 /ara.pl | |
parent | 4ae42289c9615ecdb8ebc4889d35a79f566ba428 (diff) | |
download | ara-fbc0e48541b10b743e5376ffe69943ce40a871f5.tar.gz |
Change output format to tables
This version is much better, it will print all states information along with delta in some fields like confirmed, deaths, recovered. I'm not sure though if this is the best way, it just works.
Diffstat (limited to 'ara.pl')
-rwxr-xr-x | ara.pl | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/ara.pl b/ara.pl index 78121e9..ea256b8 100755 --- a/ara.pl +++ b/ara.pl @@ -4,11 +4,11 @@ use strict; use warnings; use feature 'say'; -use YAML qw( Bless Dump ); use Path::Tiny; use File::Fetch; use Data::Dumper; -use JSON::MaybeXS; +use JSON::MaybeXS qw( decode_json ); +use Text::Table::Tiny qw( generate_table ); use OpenBSD::Unveil; @@ -52,8 +52,26 @@ unveil() or # Decode $file_data to $json_data. my $json_data = decode_json($file_data); -# Print total. -my $total = $json_data->{'statewise'}[0]; +# Get statewise information. +my @statewise = ${$json_data}{'statewise'}; -Bless($total)->keys( ['confirmed', 'recovered', 'active', 'deaths'] ); -print Dump $total; +my $rows = [ + ['State', 'Confirmed', 'Active', 'Recovered', 'Deaths'], + ]; + +# Add first 37 entries to $rows. +foreach my $i (0...37) { + push @$rows, [ + # Limit the length to 18 characters, this will cut long state + # names. + substr( $statewise[0][$i]{'state'}, 0, 18 ), + + "$statewise[0][$i]{'confirmed'} (+$statewise[0][$i]{'deltaconfirmed'})" , + $statewise[0][$i]{'active'}, + "$statewise[0][$i]{'recovered'} (+$statewise[0][$i]{'deltadeaths'})", + "$statewise[0][$i]{'deaths'} (+$statewise[0][$i]{'deltarecovered'})", + ]; +} + +# Generate table. +say generate_table(rows => $rows, header_row => 1); |