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
1 changed files with 4 additions and 5 deletions

View File

@ -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 {