77 lines
1.7 KiB
Perl
Executable File
77 lines
1.7 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
#
|
|
use strict;
|
|
use warnings;
|
|
use RRDs;
|
|
use Data::Dumper;
|
|
use Template;
|
|
|
|
my $file = $ARGV[0] or die("Usage: $0 csv\n");
|
|
|
|
my $rrdpath = "/var/www/localhost/rrd";
|
|
my $cryptoMap = {
|
|
"AAVE" => "AAVE",
|
|
"ALGO" => "Algorand",
|
|
"BTC" => "Bitcoin",
|
|
"CVC" => "Civic",
|
|
"DNT" => "district0x",
|
|
"DOGE" => "Dogecoin",
|
|
"EGLD" => "Elrond eGold",
|
|
"ETH" => "Etherium",
|
|
"EOS" => "EOS",
|
|
"LRC" => "Loopring",
|
|
"RAD" => "Radicle",
|
|
"REN" => "REN",
|
|
"SHIB" => "Shiba Inu",
|
|
"SNX" => "Synthetix",
|
|
"XLM" => "Stellar Lumen",
|
|
"XTZ" => "Tezos",
|
|
"ZRX" => "Ox",
|
|
};
|
|
my $v;
|
|
|
|
$v->{GENERATED} = localtime;
|
|
|
|
sub getCurrentPrice {
|
|
my ($symbol) = @_;
|
|
my ($start,$step,$name,$data) = RRDs::fetch("${rrdpath}/crypto-${symbol}.rrd","LAST","--start","-10m");
|
|
return($data->[0]->[0] || 0);
|
|
}
|
|
|
|
sub getLastWeekValue {
|
|
my ($symbol) = @_;
|
|
my ($start,$step,$name,$data) = RRDs::fetch("${rrdpath}/crypto-${symbol}.rrd","AVERAGE","--start","-7d");
|
|
return($data->[0]->[0] || 1);
|
|
}
|
|
|
|
open(CSV,"<$file") or die("open($file): $!\n");
|
|
|
|
while (<CSV>) {
|
|
my ($date,$currency,$coin,$price,$fee,$buyrate,$selltresh) = split /;/;
|
|
my $x = {
|
|
DATE => $date,
|
|
NAME => $cryptoMap->{$currency},
|
|
CURRENCY => $currency,
|
|
COIN => $coin,
|
|
PRICE => $price,
|
|
FEE => $fee,
|
|
BUYRATE => $buyrate,
|
|
};
|
|
$x->{CURRENT_PRICE} = &getCurrentPrice($currency);
|
|
$x->{LAST_WEEK_PRICE} = &getLastWeekValue($currency);
|
|
$x->{IMAGE} = `curl -s 'http://localhost/cgi-bin/graph.pl?width=540&height=200&graph=crypto-${currency}&start=-14d' --output - | base64`;
|
|
push @{$v->{DATA}},$x;
|
|
}
|
|
|
|
close(CSV);
|
|
|
|
my $template = Template->new({
|
|
INCLUDE_PATH => '/var/www/localhost/tmpl',
|
|
INTERPOLATE => 1,
|
|
});
|
|
|
|
$|++;
|
|
$template->process('cryptoReport.tmpl',$v) or die($!);
|
|
print "\n";
|
|
#print Dumper($v);
|