From 9c69878d9ae8f925a16ad5beeaa9f4c1686fd79c Mon Sep 17 00:00:00 2001 From: Arne Baeumler Date: Sat, 6 Feb 2021 16:19:34 +0100 Subject: [PATCH] html crypto report --- .gitignore | 2 ++ scripts/cryptoReport.pl | 71 +++++++++++++++++++++++++++++++++++++++++ scripts/mail-header | 6 ++++ tmpl/cryptoReport.tmpl | 63 ++++++++++++++++++++++++++++++++++++ 4 files changed, 142 insertions(+) create mode 100755 scripts/cryptoReport.pl create mode 100644 scripts/mail-header create mode 100644 tmpl/cryptoReport.tmpl diff --git a/.gitignore b/.gitignore index 97df448..f7ed52f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ src test rrd/*.rrd *.ok +*.bak config/*cfg_l_* +htdocs/cryptoPortfolio.html diff --git a/scripts/cryptoReport.pl b/scripts/cryptoReport.pl new file mode 100755 index 0000000..48fd1e9 --- /dev/null +++ b/scripts/cryptoReport.pl @@ -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 () { + 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); diff --git a/scripts/mail-header b/scripts/mail-header new file mode 100644 index 0000000..0c428a2 --- /dev/null +++ b/scripts/mail-header @@ -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 + diff --git a/tmpl/cryptoReport.tmpl b/tmpl/cryptoReport.tmpl new file mode 100644 index 0000000..1b492e0 --- /dev/null +++ b/tmpl/cryptoReport.tmpl @@ -0,0 +1,63 @@ +[% USE f2 = format('%.2f') %] + + + + + +

Report vom [% GENERATED %]

+

Aktueller Report

+ +[% totalProfit = 0 %] +[% FOREACH c IN DATA %] +[% gain = f2(c.CURRENT_PRICE / c.LAST_WEEK_PRICE * 100 - 100) %] + + + + +[% totalProfit = totalProfit + f2((c.CURRENT_PRICE * c.COIN) - c.PRICE) %] +[% END %] +
[% c.NAME %] + + + + + + + +[% IF gain > 0 %] + +[% ELSE %] + +[% END %] +
Währung[% c.NAME %] ([% c.CURRENCY %])
Kaufdatum[% c.DATE %]
Kaufpreis[% f2(c.BUYRATE) %] Euro/[% c.CURRENCY %]
aktueller Kurs[% f2(c.CURRENT_PRICE) %] Euro/[% c.CURRENCY %]
aktueller Wert[% f2(c.CURRENT_PRICE * c.COIN) %] Euro
aktueller Profit[% f2((c.CURRENT_PRICE * c.COIN) - c.PRICE) %] Euro
7 Tage Gewinn+[% gain %] %
7 Tage Verlust[% gain %] %
+
+

Gewinn (gesamt) ca. [% totalProfit %] Euro

+ +