html crypto report
This commit is contained in:
parent
ce88578302
commit
9c69878d9a
2
.gitignore
vendored
2
.gitignore
vendored
@ -3,4 +3,6 @@ src
|
|||||||
test
|
test
|
||||||
rrd/*.rrd
|
rrd/*.rrd
|
||||||
*.ok
|
*.ok
|
||||||
|
*.bak
|
||||||
config/*cfg_l_*
|
config/*cfg_l_*
|
||||||
|
htdocs/cryptoPortfolio.html
|
||||||
|
71
scripts/cryptoReport.pl
Executable file
71
scripts/cryptoReport.pl
Executable file
@ -0,0 +1,71 @@
|
|||||||
|
#!/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",
|
||||||
|
"EGLD" => "Elrond eGold",
|
||||||
|
"ETH" => "Etherium",
|
||||||
|
"LRC" => "Loopring",
|
||||||
|
"REN" => "REN",
|
||||||
|
"SNX" => "Synthetix",
|
||||||
|
"XLM" => "Stellar Lumen",
|
||||||
|
"XTZ" => "Tezos"
|
||||||
|
};
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub getLastWeekValue {
|
||||||
|
my ($symbol) = @_;
|
||||||
|
my ($start,$step,$name,$data) = RRDs::fetch("${rrdpath}/crypto-${symbol}.rrd","AVERAGE","--start","-7d");
|
||||||
|
return($data->[0]->[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 -w 0`;
|
||||||
|
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);
|
6
scripts/mail-header
Normal file
6
scripts/mail-header
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
To: baeumler85@gmx.net, arne@br0tkasten.de
|
||||||
|
Subject: "Crypto Report"
|
||||||
|
MIME-Version: 1.0
|
||||||
|
Content-Type: text/html
|
||||||
|
Content-Disposition: inline
|
||||||
|
|
63
tmpl/cryptoReport.tmpl
Normal file
63
tmpl/cryptoReport.tmpl
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
[% USE f2 = format('%.2f') %]
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: Helvetica,Arial;
|
||||||
|
}
|
||||||
|
table {
|
||||||
|
width: 100vw;
|
||||||
|
}
|
||||||
|
th {
|
||||||
|
text-align: left;
|
||||||
|
font-weight: bold;
|
||||||
|
border-bottom: 1px solid #808080;
|
||||||
|
}
|
||||||
|
td {
|
||||||
|
text-align: right;
|
||||||
|
padding: 0em 1em;
|
||||||
|
border-bottom: 1px solid #808080;
|
||||||
|
}
|
||||||
|
.gain {
|
||||||
|
font-weight: bold;
|
||||||
|
color: #f0f0f0;
|
||||||
|
background-color: #269900;
|
||||||
|
}
|
||||||
|
.loss {
|
||||||
|
font-weight: bold;
|
||||||
|
color: #f0f0f0;
|
||||||
|
background-color: #cc0000;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Report vom [% GENERATED %]</h1>
|
||||||
|
<h4><a href="https://mrtg.br0tkasten.de/cryptoPortfolio.html">Aktueller Report</a></h4>
|
||||||
|
<table>
|
||||||
|
[% totalProfit = 0 %]
|
||||||
|
[% FOREACH c IN DATA %]
|
||||||
|
[% gain = f2(c.CURRENT_PRICE / c.LAST_WEEK_PRICE * 100 - 100) %]
|
||||||
|
<tr>
|
||||||
|
<td><img alt="[% c.NAME %]" src="data:image/png;base64,[% c.IMAGE %]"></td>
|
||||||
|
<td>
|
||||||
|
<table>
|
||||||
|
<tr><th>Währung</th><td>[% c.NAME %] ([% c.CURRENCY %])</td></tr>
|
||||||
|
<tr><th>Kaufdatum</th><td>[% c.DATE %]</td></tr>
|
||||||
|
<tr><th>Kaufpreis</th><td>[% f2(c.BUYRATE) %] Euro/[% c.CURRENCY %]</td></tr>
|
||||||
|
<tr><th>aktueller Kurs</th><td>[% f2(c.CURRENT_PRICE) %] Euro/[% c.CURRENCY %]</td></tr>
|
||||||
|
<tr><th>aktueller Wert</th><td>[% f2(c.CURRENT_PRICE * c.COIN) %] Euro</td></tr>
|
||||||
|
<tr><th>aktueller Profit</th><td><b>[% f2((c.CURRENT_PRICE * c.COIN) - c.PRICE) %] Euro</b></td></tr>
|
||||||
|
[% IF gain > 0 %]
|
||||||
|
<tr class="gain"><td>7 Tage Gewinn</td><td>+[% gain %] %</td></tr>
|
||||||
|
[% ELSE %]
|
||||||
|
<tr class="loss"><td>7 Tage Verlust</td><td>[% gain %] %</td></tr>
|
||||||
|
[% END %]
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
[% totalProfit = totalProfit + f2((c.CURRENT_PRICE * c.COIN) - c.PRICE) %]
|
||||||
|
[% END %]
|
||||||
|
</table>
|
||||||
|
<h2>Gewinn (gesamt) ca. [% totalProfit %] Euro</h2>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
x
Reference in New Issue
Block a user