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

Re^2: calculating planet conjunction with mojo front end

by Aldebaran (Curate)
on Dec 12, 2020 at 07:33 UTC ( [id://11125050]=note: print w/replies, xml ) Need Help??


in reply to Re: calculating planet conjunction with mojo front end
in thread calculating planet conjunction with mojo front end

'Goal 3' if you look at previous threads of yours I've provided Mojo based implementations of similar sounding things already, or at least enough to leverage as a starting point for delivering this. The code you post here is not Mojo based. What did you try and how did it fail?

I looked through what you posted on my questions, and we were looking at this in April and May of this year, and I was very keen to know where the sun was going to be then. Many of the scripts I wrote then were mishmashes: I was experimenting, and it would all ultimately not get off the ground on my shared server.

Then we had the perl conference, my first, and I realized everything had to change because everything had changed.

$ pwd /home/hogan/mojo $ ls 1.button.pl 5.3.elev.debug.pl 5.3.elev.pl $

Q1) How do grown-ups configure their mojo capability on their development machine? Is it, like me right, a single directory that will eventually have dozens of files with names that look almost the same. The way I can guess which one works is what has the highest number. But this can also be where I gave up the ghost on a string of bad ideas expressed in script.

Q2) Since I have perlbrew on the remote server (recommended by mojo), should I install it on the laptop, i.e. the development machine?

Let's tack to what parts work. Output, then source.

2020/12/11 10:45:52 INFO ./3.mojo_fermi.pl 2020/12/11 10:45:53 INFO i is 0 ============== 2020/12/11 10:45:53 INFO <?xml version="1.0" encoding="iso-8859-1"?> 2020/12/11 10:45:53 INFO i is 1 ============== 2020/12/11 10:45:53 INFO 2020/12/11 10:45:53 INFO i is 2 ============== 2020/12/11 10:45:53 INFO <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 +Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2020/12/11 10:45:53 INFO i is 3 ============== 2020/12/11 10:45:53 INFO 2020/12/11 10:45:53 INFO i is 4 ============== 2020/12/11 10:45:53 INFO <html lang="en" xml:lang="en" xmlns="http://w +ww.w3.org/1999/xhtml"> <head> <title> Sky above 45°31&#39;5&quot;N 122°40&#39;33&quot;W at Fri 2020 Dec 11 1 +8:45 </title> </head> <body> snip <p /> <a href="/yoursky/help/ephemeris.html"><b>Ephemeris:</b></a><center> <table border="border" cellpadding="3"> <tr><th rowspan="2"> </th><th rowspan="2">Right<br />Ascension</th><th + rowspan="2">Declination</th><th rowspan="2">Distance<br />(<span tit +le="Astronomical units (149,597,871 km)">AU</span>)</th><th colspan=" +2">From 45°31&#39;5&quot;N 122°40&#39;33&quot;W:</th></tr> <tr><th>Altitude</th><th>Azimuth</th></tr> <tr><th><a href="/cgi-bin/uncgi/Yourtel?aim=0&amp;z=1">Sun</a></th><td + align="right">17h 17m 17s</td><td align="right">&#8722;23° 4.4&#39;< +/td><td align="right">0.985</td><td align="right">19.130</td><td alig +n="right">&#8722;19.052</td><td>Up</td></tr> <tr><th><a href="/cgi-bin/uncgi/Yourtel?aim=1&amp;z=1">Mercury</a></th +><td align="right">16h 56m 57s</td><td align="right">&#8722;23° 19.1& +#39;</td><td align="right">1.438</td><td align="right">19.910</td><td + align="right">&#8722;14.157</td><td>Up</td></tr> <tr><th><a href="/cgi-bin/uncgi/Yourtel?aim=2&amp;z=1">Venus</a></th>< +td align="right">15h 32m 32s</td><td align="right">&#8722;17° 41.8&#3 +9;</td><td align="right">1.480</td><td align="right">26.501</td><td a +lign="right">7.028</td><td>Up</td></tr> <tr><th><a href="/cgi-bin/uncgi/Yourtel?aim=3&amp;z=1">Moon</a></th><t +d align="right">14h 35m 51s</td><td align="right">&#8722;11° 41.4&#39 +;</td><td align="right">57.0 <span title="Earth radii (6378.14 km)">E +R</span></td><td align="right">29.801</td><td align="right">23.591</t +d><td>Up</td></tr> <tr><th><a href="/cgi-bin/uncgi/Yourtel?aim=4&amp;z=1">Mars</a></th><t +d align="right">1h 12m 37s</td><td align="right">+8° 4.4&#39;</td><td + align="right">0.725</td><td align="right">&#8722;24.754</td><td alig +n="right">&#8722;133.649</td><td>Set</td></tr> <tr><th><a href="/cgi-bin/uncgi/Yourtel?aim=5&amp;z=1">Jupiter</a></th +><td align="right">20h 2m 11s</td><td align="right">&#8722;20° 57.3&# +39;</td><td align="right">5.841</td><td align="right">3.667</td><td a +lign="right">&#8722;54.781</td><td>Up</td></tr> <tr><th><a href="/cgi-bin/uncgi/Yourtel?aim=6&amp;z=1">Saturn</a></th> +<td align="right">20h 6m 43s</td><td align="right">&#8722;20° 37.7&#3 +9;</td><td align="right">10.733</td><td align="right">3.271</td><td a +lign="right">&#8722;55.819</td><td>Up</td></tr> <tr><th><a href="/cgi-bin/uncgi/Yourtel?aim=7&amp;z=1">Uranus</a></th> +<td align="right">2h 20m 0s</td><td align="right">+13° 28.6&#39;</td> +<td align="right">19.043</td><td align="right">&#8722;26.910</td><td +align="right">&#8722;152.851</td><td>Set</td></tr> <tr><th><a href="/cgi-bin/uncgi/Yourtel?aim=8&amp;z=1">Neptune</a></th +><td align="right">23h 18m 20s</td><td align="right">&#8722;5° 39.9&# +39;</td><td align="right">29.945</td><td align="right">&#8722;17.891< +/td><td align="right">&#8722;100.409</td><td>Set</td></tr> <tr><th><a href="/cgi-bin/uncgi/Yourtel?aim=9&amp;z=1">Pluto</a></th>< +td align="right">19h 41m 19s</td><td align="right">&#8722;22° 34.9&#3 +9;</td><td align="right">34.999</td><td align="right">5.255</td><td a +lign="right">&#8722;49.911</td><td>Up</td></tr> </table> </center> <blockquote> snip </body> </html> 2020/12/11 10:45:53 INFO i is 5 ============== 2020/12/11 10:45:53 INFO

Source:

#!/usr/bin/perl use strict; use warnings; use Mojo::URL; use Mojo::Util qw(dumper); use Mojo::UserAgent; use Data::Dump; use Log::Log4perl; use 5.016; use Mojo::DOM; my $log_conf3 = "/home/hogan/Documents/hogan/logs/conf_files/3.conf"; my $log_conf4 = "/home/hogan/Documents/hogan/logs/conf_files/4.conf"; #Log::Log4perl::init($log_conf3); #debug Log::Log4perl::init($log_conf4); #info my $logger = Log::Log4perl->get_logger(); $logger->info("$0"); my $site = 'https://www.fourmilab.ch/cgi-bin/Yoursky?z=1&lat=45.5183&ns=North&lon +=122.676&ew=West'; # pretend to be a browser 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->max_redirects(5)->connect_timeout(20)->request_timeout(20); $ua->transactor->name($uaname); # find search results my $dom = $ua->get($site)->res->dom; # dd $dom; #overwhelms STDOUT say "==========="; my @nodes = @$dom; # c-style for is good for array output with index for ( my $i = 0 ; $i < @nodes ; $i++ ) { $logger->info("i is $i =============="); $logger->info("$nodes[$i]"); } sleep 2; #good hygiene __END__

The ephemeris is when i=4 here. That's where we are gonna be fishing for values.

The mojo syntax for tables is...idiomatic, but you gave me an example in Re: polishing up a json fetching script for weather data. Excerpting your response:

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;

So now I need to adapt this for Saturn and Jupiter, but I don't want to hard code that part this time: they should be selected. I think I can get this done with 2 sets of radio buttons, if a pull-down menu is more than I want to bite off at this point. So that's where I am tonight.

I haven't started coding anew, wanting to rather begin with a reasonable write-up. Thanks for your comments,

Replies are listed 'Best First'.
Re^3: calculating planet conjunction with mojo front end
by marto (Cardinal) on Dec 12, 2020 at 17:24 UTC

    Q1) In terms of Mojolicious see Tutorial which introduces Mojolicious::Lite, where Growing takes you from Mojolicious::Lite to a more structured Mojolicious app, which may be overkill depending on your needs. In terms of development, look into version control, something like Git, the docs have some videos giving overviews etc. By using something along these lines you negate the need to keep multiple copies of the same thing (or very similar), with different names in an attempt to keep track of which changes broke what.

    Q2) Best practice to try and stick to the same perl and Mojolicious versions.

    "The mojo syntax for tables is...idiomatic"

    "So now I need to adapt this for Saturn and Jupiter, but I don't want to hard code that part this time: they should be selected. I think I can get this done with 2 sets of radio buttons, if a pull-down menu is more than I want to bite off at this point. So that's where I am tonight."

    As mentioned previously these are CSS selectors, $sunrow shows how to get the table row for the Sun. You'd just have to alter this selector based upon values from a drop down (or whatever) to select the details for the rows you wanted. You could even dynamically populate the drop down (or whatever) based on the values from the column in question. That said, if you are looking to host something yourself, I don't see why you're scraping this other site. Wouldn't it make more sense to calculate this stuff yourself? A very helpful Anonymous Monk has given some examples using the Astro namespace modules, Re^2: calculating planet conjunction with mojo front end for example.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-03-29 14:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found