Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: polishing up a json fetching script for weather data

by marto (Cardinal)
on May 24, 2020 at 10:18 UTC ( [id://11117194]=note: print w/replies, xml ) Need Help??


in reply to Re^2: polishing up a json fetching script for weather data
in thread polishing up a json fetching script for weather data

I don't understand the reason behind the various approaches rather than keep things clean and just sticking with the Mojo based solution for everything. I thought there would be a better, local way to get whatever data you are looking for, but I'm not an astronomer. If Astro::Coord::ECI::Sun does this then I don't see any problem in just calling that as many times as you require.

  • Comment on Re^3: polishing up a json fetching script for weather data

Replies are listed 'Best First'.
Re^4: polishing up a json fetching script for weather data
by Aldebaran (Curate) on May 27, 2020 at 08:32 UTC
    I don't understand the reason behind the various approaches rather than keep things clean and just sticking with the Mojo based solution for everything.

    The approaches I was using are ones I understand. First with WWW::Mechanize, which I've used on that site for years. I haven't worked up the facility to do it with Mojo yet, despite many attempts. What happens is that I try to extend the script in a small way and can't quite get there. You said if I ran into the weeds again, let you know, so let's try this one, because it's where I was/am stuck with mojo.

    I'm trying to enter the site at the beginning and mechanize my way through to the table I need after the initial sky map has been made. I tried commands like this to tell me something about the page:

    $ mojo get https://www.fourmilab.ch/yoursky/ '*' attr id skylat skynsn skynss skylon skyewe skyeww horlat hornsn hornss horlon horewe horeww feedback $

    I see 2 of the fields I need to populate here, but I don't know how to deal with the button in the mojo context. In your successful upthread script, you seem not to use a click_button event to get it done, so I tried to squeak by the same way:

    $ ./3.mo_scrape.pl ./3.mo_scrape.pl 45.5 -122.4 0.346 Can't call method "children" on an undefined value at ./3.mo_scrape.pl + line 45. $ cat 3.mo_scrape.pl #!/usr/bin/env perl use Mojo::UserAgent; use 5.016; use warnings; use Mojo::UserAgent; use DateTime::Format::Strptime; use open ':std', OUT => ':utf8'; use Mojo::DOM; use Log::Log4perl; # get rid of old log my $file = '/home/hogan/Documents/hogan/logs/4.log4perl.txt'; unlink $file or warn "Could not unlink $file: $!"; my $log_conf4 = "/home/hogan/Documents/hogan/logs/conf_files/4.conf"; Log::Log4perl::init($log_conf4); #info my $logger = Log::Log4perl->get_logger(); $logger->info("$0"); ## important...no trailing zeroes else 301 error my $lat = 45.5; my $long = -122.4; my $elev = .346; #km $logger->info("$lat $long $elev"); my $guess = 2458960; #Earth day 2020 in julian days my $west_long = -$long; # the API docs says you must identify yourself, please make this somet +hing legit # my $name = '(example.com, contact@example.com)'; # can't I pretend to be a browser like any other? my $uaname = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like G +ecko) Chrome/40.0.2214.93 Safari/537.36'; my $ua = Mojo::UserAgent->new; $ua->transactor->name($uaname); my $pturl = 'https://www.fourmilab.ch/yoursky/'; my $tx = $ua->post( $pturl => form => { skylat => $lat, skylon => $west_long +} ); $tx = $ua->post( $pturl => form => { utc => $guess, date => '2' } ); my $sunrow = $tx->res->dom->at('center:nth-of-type(3) table tr:n./2th- +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; $

    Q1) How do I lose this one? (I'd like to see the equivalent of $mech->uri) If I need the button it would have to look something like submit_button:

    %= submit_button 'Ok!', id => 'foo'

    Q2) What gives with the %= symbol on the left?

    I thought there would be a better, local way to get whatever data you are looking for, but I'm not an astronomer.

    I took Stellar Evolution my final semester in physics. I was doing alright until the final turned out to be a computer project that was to integrate a star given a certain composition (no idea what syntax). I was caught completely flatfooted and had somewhat of a meltdown, where I decided to continue my degree with mathematics instead. The failure has stung through the decades.

    If Astro::Coord::ECI::Sun does this then I don't see any problem in just calling that as many times as you require.

    Copy that.

      Q1: Tag helpers are convenient ways within Mojo tempaltes to generate HTML, e.g.

      %= submit_button 'Ok!', id => 'foo'

      Generates the HTML:

      <input id="foo" type="submit" value="Ok!">

      At this stage in your script I don't see anything for generating pages. Are you confusing this perhaps with submitting forms? In my example I just used the Mojo::UserAgent post method to submit the form. Basic investigation of the html shows what we need to submit to get the desired results.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11117194]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2024-04-18 12:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found