diff options
author | Andinus <andinus@nand.sh> | 2020-05-29 10:38:58 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2020-05-29 10:38:58 +0530 |
commit | 17defcc48e8e442703e796884327383a289d6fb8 (patch) | |
tree | b1d70ee9a39baa766cee6854868d00bb56c20ade /ara.pl | |
parent | 7ef11163b78678b1b592265e5a02e914cfcc778e (diff) | |
download | ara-17defcc48e8e442703e796884327383a289d6fb8.tar.gz |
Initial version
Diffstat (limited to 'ara.pl')
-rwxr-xr-x | ara.pl | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/ara.pl b/ara.pl new file mode 100755 index 0000000..78121e9 --- /dev/null +++ b/ara.pl @@ -0,0 +1,59 @@ +#!/usr/bin/perl + +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 OpenBSD::Unveil; + +# Unveil @INC. +foreach my $path (@INC) { + unveil( $path, 'rx' ) or + die "Unable to unveil: $!"; +} + +# %unveil contains list of paths to unveil with their permissions. +my %unveil = ( + "/" => "rx", # Unveil "/", remove this later after profiling with + # ktrace. + "/home" => "", # Veil "/home", we don't want to read it. + "/tmp" => "rwc", + "/dev/null" => "rw", + ); + +# Unveil each path from %unveil. +keys %unveil; +while( my( $path, $permission ) = each %unveil ) { + unveil( $path, $permission ) or + die "Unable to unveil: $!"; +} + +# Fetch latest data from api. +my $url = 'https://api.covid19india.org/data.json'; +my $ff = File::Fetch->new(uri => $url); + +# Save the api response under /tmp. +my $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: $!"; + +# Decode $file_data to $json_data. +my $json_data = decode_json($file_data); + +# Print total. +my $total = $json_data->{'statewise'}[0]; + +Bless($total)->keys( ['confirmed', 'recovered', 'active', 'deaths'] ); +print Dump $total; |