in reply to bitcoin price from command line

Here's a basic example using Mojo::UserAgent:

use feature 'say'; use Mojo::UserAgent; my $ua = Mojo::UserAgent->new; my $coinbaseURL = 'https://api.coindesk.com/v1/bpi/currentprice/usd.js +on'; my $value = $ua->get( $coinbaseURL )->result->json->{bpi}{USD}{rate}; say "Bitcoin Price (USD): $value";

If I were doing such a thing I'd likely just use Mojolicious::Lite for the site/page, and create a little route based on the example above (throw in some error checking etc) to return this as json, and call that route on the page every few minutes via JavaScript, so that the Bitcoin price updated without having to refresh/reload the page, from expedience tends to be how users expect things to work these days. See also Mojolicious -> Tutorial and UserAgent.

Replies are listed 'Best First'.
Re^2: bitcoin price from command line
by hippo (Archbishop) on Jan 08, 2019 at 12:13 UTC
    from expedience tends to be how users expect things to work these days.

    While I don't disagree, I would like to add a small request that anyone writing such pages also includes a simple Off Switch in order to cater for the expectations of the rest of us. Reading a page only to have it unexpectedly change on you is only slightly less annoying than those move-elements-around-while-the-page-builds renderers which invariably result in clicking on the wrong thing that's just magically moved under the pointer.

    I'll just crawl back to my web 1.0 now.

      Yes, much of the interwebs for me is just broken :)

Re^2: bitcoin price from command line
by *alexandre* (Scribe) on Jan 08, 2019 at 12:56 UTC
    Hi first thanks for your time, I used the following code
    #!/usr/bin/perl -w use feature 'say'; use Mojo::UserAgent; my $ua = Mojo::UserAgent->new; my $coinbaseURL = 'https://api.coindesk.com/v1/bpi/currentprice/usd.js +on'; my $value = $ua->get( $coinbaseURL )->result->json->{bpi}{USD}{rate}; #say "Bitcoin Price (USD): $value"; print "Content-Type: text/html\n\n"; print "Bitcoin Price (USD): $value";
    But I got the following error :
    [error] [client 127.0.0.1] IO::Socket::SSL 2.009+ required for TLS sup +port at /home/alexandre/apache/cgi-bin/helloWorld.cgi line 10.
    EDIT : After upgrading IO::Socket::SSL it's work fine thanks you guys

      Mojo::UserAgent uses various modules for TLS and so on, if they're available (see Description). Either (ideally) install IO::Socket::SSL, or alternatively set the appropriate environment variable to disable the functionality, the first suggestion is better.