diff --git a/bin/bitcoin_monitor.pl b/bin/bitcoin_monitor.pl index e3eb927..de61758 100755 --- a/bin/bitcoin_monitor.pl +++ b/bin/bitcoin_monitor.pl @@ -22,16 +22,15 @@ my $run_once = defined $ARGV[0]; while (1) { say "Searching data" if !$run_once; eval { - my $result = $ua->get(q(https://www.coingecko.com/))->result->body; + my $result = $ua->get('https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=bitcoin')->result->body; my $eur_result = $ua->get(q(https://duckduckgo.com/js/spice/currency/1/USD/EUR)) ->result->body; $eur_result = $eur_result =~ s/^ddg_spice_currency\(//r =~ s/\);$//r; + $result = $result =~ s/^ddg_spice_currency\(//r =~ s/\);$//r; $eur_result = decode_json($eur_result); - my $dom = Mojo::DOM->new($result); - my $bitcoin = $dom->at(q(.coin-table)) - ->at(q(span[data-coin-symbol="btc"][data-target="price.price"])); - my $bitcoin_price = $bitcoin->all_text =~ s/,//gr =~ s/\$//r; + $result = decode_json($result); + my $bitcoin_price = $result->[0]{current_price}; printf "%.02f€ \$%0.2f\n", $bitcoin_price * 0.00257 * $eur_result->{conversion}->{q/converted-amount/}, $bitcoin_price; local $SIG{ALRM} = sub {