From 5a32f162919ead29f9a83d99f715dd5dee3257b6 Mon Sep 17 00:00:00 2001 From: sergiotarxz Date: Mon, 28 Mar 2022 16:18:52 +0200 Subject: [PATCH] Fixing the bitcoin scrapper to use the api. We got into the cloudflare bad eyes. Fuck cloudflare. --- bin/bitcoin_monitor.pl | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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 {