2020/12/11 00:28:28 INFO ./4.wm_fermi.pl 2020/12/11 00:28:33 INFO right ascension of jupiter 20h 11m 7s 2020/12/11 00:28:33 INFO right ascension of saturn 20h 11m 3s 2020/12/11 00:28:33 INFO jup seconds is 72667 2020/12/11 00:28:33 INFO sat seconds is 72663 2020/12/11 00:28:38 INFO right ascension of jupiter 20h 10m 16s 2020/12/11 00:28:38 INFO right ascension of saturn 20h 10m 38s 2020/12/11 00:28:38 INFO jup seconds is 72616 2020/12/11 00:28:38 INFO sat seconds is 72638 2020/12/11 00:28:42 INFO right ascension of jupiter 20h 10m 38s 2020/12/11 00:28:42 INFO right ascension of saturn 20h 10m 49s 2020/12/11 00:28:42 INFO jup seconds is 72638 2020/12/11 00:28:42 INFO sat seconds is 72649 2020/12/11 00:28:47 INFO right ascension of jupiter 20h 10m 53s 2020/12/11 00:28:47 INFO right ascension of saturn 20h 10m 56s 2020/12/11 00:28:47 INFO jup seconds is 72653 2020/12/11 00:28:47 INFO sat seconds is 72656 2020/12/11 00:28:51 INFO right ascension of jupiter 20h 11m 0s 2020/12/11 00:28:51 INFO right ascension of saturn 20h 11m 0s 2020/12/11 00:28:51 INFO jup seconds is 72660 2020/12/11 00:28:51 INFO sat seconds is 72660 2020/12/11 00:28:51 INFO equal, while condition fails at julian day 2459205.07717792 2020/12/11 00:28:51 INFO equal seconds is 72660 #### #!/usr/bin/env perl use warnings; use strict; use 5.010; use WWW::Mechanize; use HTML::TableExtract qw(tree); use open ':std', OUT => ':utf8'; use Prompt::Timeout; use constant TIMEOUT => 3; use constant MAXTRIES => 30; use Log::Log4perl; ## redesign for jupiter/saturn conjunction 2020 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 = 'http://www.fourmilab.ch/yoursky/cities.html'; my $mech = WWW::Mechanize->new; $mech->get($site); $mech->follow_link( text => 'Portland OR' ); my $before_bound = 2459203.5; #before conjunction my $after_bound = 2459206.5; #after conjunction $mech->set_fields(qw'date 2'); my ( $moon_seconds, $sun_seconds ) = ( 5, 3 ); # unequal values to start script chugging my $upper = $after_bound; my $lower = $before_bound; my ( $equal, $equal_sec ); my $attempts = 1; while ( ( $sun_seconds != $moon_seconds ) ) { my $default = ( ( $attempts >= MAXTRIES ) ) ? 'N' : 'Y'; my $answer = prompt( "Make query number $attempts?", $default, TIMEOUT ); exit if $answer =~ /^N/i; my $guess = closetohalf( $upper, $lower ); $mech->set_fields( jd => $guess ); $mech->click_button( value => "Update" ); my $te = 'HTML::TableExtract'->new; $te->parse( $mech->content ); my $table = ( $te->tables )[3]; my $table_tree = $table->tree; my $moon = $table_tree->cell( 7, 1 )->as_text; $logger->info("right ascension of jupiter $moon"); my $sun = $table_tree->cell( 8, 1 )->as_text; $logger->info("right ascension of saturn $sun"); $moon_seconds = string_to_second($moon); $logger->info("jup seconds is $moon_seconds"); $sun_seconds = string_to_second($sun); $logger->info("sat seconds is $sun_seconds"); if ( $sun_seconds < $moon_seconds ) { $upper = $guess; } elsif ( $moon_seconds < $sun_seconds ) { $lower = $guess; } else { $equal = $guess; $logger->info("equal, while condition fails at julian day $equal"); $equal_sec = $moon_seconds; } $te->delete; $attempts++; } $logger->info("equal seconds is $equal_sec"); sub string_to_second { my $string = shift; my $return = 9000; if ( my $success = $string =~ /^(\d*)h\s+(\d*)m\s+(\d*)s$/ ) { $return = 3600 * $1 + 60 * $2 + $3; } else { # log the error $logger->error("string was misformed $string"); die "string was misformed $!"; } return $return; } sub closetohalf { my ( $up, $low ) = @_; $low + ( $up - $low ) * ( 0.4 + rand 0.2 ); } #### fred@fourth:~/mojo$ ls 1.button.pl 2.1.mojo_hello.pl 5.3.elev.debug.pl 1.myapp.pl 5.2.elev.pl 5.3.elev.pl fred@fourth:~/mojo$