in reply to bitcoin price from command line

Using my module HTTP::Request::FromCurl or it's associated online website, curl2lwp, you can conveniently convert any curl command to Perl.

#!perl use strict; use warnings; use WWW::Mechanize; use HTTP::Request; my $ua = WWW::Mechanize->new(); my $r = HTTP::Request->new( 'GET' => 'https://api.coindesk.com/v1/bpi/currentprice/usd.json', [ 'Accept' => '*/*', 'Host' => 'api.coindesk.com:443', 'User-Agent' => 'curl/7.55.1', ], ); my $res = $ua->request( $r, ); __END__ Created from curl command line curl -s https://api.coindesk.com/v1/bpi/currentprice/usd.json

Reading and extracting the rate from the JSON file is easiest done using the JSON module (or JSON::PP or JSON::XS or ...), which convert the JSON to a nice data structure which you can then traverse from Perl.

Replies are listed 'Best First'.
Re^2: bitcoin price from command line
by *alexandre* (Scribe) on Jan 08, 2019 at 11:38 UTC
    Hi I follow your code and I'm getting the following error while executing my script.
    [Tue Jan 08 12:34:21 2019] [error] [client 127.0.0.1] Error GETing htt +ps://api.coindesk.com/v1/bpi/currentprice/usd.json: Can't connect to +api.coindesk.com:443 at /home/alexandre/apache/cgi-bin/helloWorld.cgi + line 20.

      Maybe you need to configure LWP::UserAgent with the HTTP proxy settings for your environment?

      $ua->env_proxy();