Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

As requested, a fairly rough and ready proof of concept using Mojo:

#!/usr/bin/perl use strict; use warnings; use feature 'say'; use Mojo::UserAgent; use DateTime::Format::Strptime; use open ':std', OUT => ':utf8'; my $url = 'https://api.weather.gov/stations/KPDX/observations/latest'; # the API docs says you must identify yourself, please make this somet +hing legit my $name = '(example.com, contact@example.com)'; my $ua = Mojo::UserAgent->new; $ua->transactor->name( $name ); # get JSON response my $json = $ua->get( $url )->res->json->{properties}; # for each cloud.... foreach my $cloud ( @{$json->{cloudLayers}} ){ say "$cloud->{amount}, $cloud->{base}{value}"; } # JD from JSON timestamp my $format = DateTime::Format::Strptime->new( pattern => '%FT%T%z'); my $dt = $format->parse_datetime( $json->{timestamp} ); say 'Julian Day: ' . $dt->jd; my $pturl = 'http://www.fourmilab.ch/cgi-bin/Yoursky?z=1&lat=45.5183& +ns=North&lon=122.676&ew=West'; # you wanted Julian date so it looks like date should be '2' from the +source. my $tx = $ua->post( $pturl => form => { utc => $dt->jd, date => '2' } +); my $sunrow = $tx->res->dom->at('center:nth-of-type(3) table tr:nth-of- +type(3)'); # output say 'Name:' . $sunrow->children->[0]->all_text; say 'Altitude: ' . $sunrow->children->[4]->text; say 'Azimuth: ' . $sunrow->children->[5]->text; say 'Visible: ' . $sunrow->children->[6]->text;

Output:

FEW, 760 SCT, 3350 BKN, 7620 Julian Day: 2458982.28680556 Name: Sun Altitude: 61.520 Azimuth: 21.289 Visible: Up

There may be some typos in there, chalk that one up to the time of day here. Let me know if there are any problems.

Update: for the 'Name' switch to all_text from text.


In reply to Re: polishing up a json fetching script for weather data by marto
in thread polishing up a json fetching script for weather data by Aldebaran

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-24 22:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found