Fixing the bitcoin scrapper to use the api.

We got into the cloudflare bad eyes.
Fuck cloudflare.
This commit is contained in:
sergiotarxz 2022-03-28 16:18:52 +02:00
parent 553245a703
commit 5a32f16291

View File

@ -22,16 +22,15 @@ my $run_once = defined $ARGV[0];
while (1) { while (1) {
say "Searching data" if !$run_once; say "Searching data" if !$run_once;
eval { 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 = my $eur_result =
$ua->get(q(https://duckduckgo.com/js/spice/currency/1/USD/EUR)) $ua->get(q(https://duckduckgo.com/js/spice/currency/1/USD/EUR))
->result->body; ->result->body;
$eur_result = $eur_result =~ s/^ddg_spice_currency\(//r =~ s/\);$//r; $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); $eur_result = decode_json($eur_result);
my $dom = Mojo::DOM->new($result); $result = decode_json($result);
my $bitcoin = $dom->at(q(.coin-table)) my $bitcoin_price = $result->[0]{current_price};
->at(q(span[data-coin-symbol="btc"][data-target="price.price"]));
my $bitcoin_price = $bitcoin->all_text =~ s/,//gr =~ s/\$//r;
printf "%.02f€ \$%0.2f\n", $bitcoin_price * 0.00257 * printf "%.02f€ \$%0.2f\n", $bitcoin_price * 0.00257 *
$eur_result->{conversion}->{q/converted-amount/}, $bitcoin_price; $eur_result->{conversion}->{q/converted-amount/}, $bitcoin_price;
local $SIG{ALRM} = sub { local $SIG{ALRM} = sub {