From d02af738364d4f49600f294e0f6f31e221b5baf5 Mon Sep 17 00:00:00 2001 From: sergiotarxz Date: Sat, 22 Jan 2022 00:39:17 +0100 Subject: [PATCH] Initial version. --- Makefile.PL | 12 ++++++++++++ bin/bitcoin_monitor.pl | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 Makefile.PL create mode 100755 bin/bitcoin_monitor.pl diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..e0cf1aa --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,12 @@ +use ExtUtils::MakeMaker; + +WriteMakefile( + NAME => 'Bitcoin::Monitor', + VERSION => '0.1', + INST_SCRIPT => './bin', + INST_BIN => './bin', + PREREQ_PM => { + 'Mojolicious' => 0, + 'Const::Fast' => 0, + } +); diff --git a/bin/bitcoin_monitor.pl b/bin/bitcoin_monitor.pl new file mode 100755 index 0000000..ec37c92 --- /dev/null +++ b/bin/bitcoin_monitor.pl @@ -0,0 +1,35 @@ +#!/usr/bin/env perl + +use v5.30.0; + +use strict; +use warnings; + +use Mojo::UserAgent; +use Mojo::DOM; + +use Const::Fast; + +const my $ALARM_NO_ERROR => q(Alarm defunction.); + +my $ua = Mojo::UserAgent->new; + +while (1) { + say "Searching data"; + eval { + my $result = $ua->get(q(https://www.coingecko.com/en))->result->body; + my $dom = Mojo::DOM->new($result); + my $bitcoin = $dom->at(q(.coin-table))->find(q(tr))->[1]; + say $bitcoin->all_text =~ s/(?:\s|\r|\n)+/ /gr; + local $SIG{ALRM} = sub { + die $ALARM_NO_ERROR; + }; + alarm 60; + my $line = ; + alarm 0; + }; + if ($@) { + STDERR->say(qq($@)) unless $@ =~ /$ALARM_NO_ERROR/; + } +} +