in reply to Re^2: Moon phase on historical events in thread Moon phase on historical events
bw from atop the Scylla
Likewise and always good to hear from you. I extended your script to attempt to determine what this moon might look like from the points we have defined and their antipodes. Any observation also needs a height which I have set at the height of Boise. I threw in the planets Venus, Saturn, and Jupiter too, as they seem to be part of the big celestial show for the next few days.
I also use Log::Log4perl, because these data would overwhelm STDOUT. The .conf files are from the examples.
My first question is how the azimuth is defined. Astro::Coord is suuuper complicated. Looks like there's even fortran in there. Physicists and mathematicians do things differently in a lot of settings. I can't tell if my results are wrong or untransformed.
The same time is used for 4 different places. (Not that they're gleichzeitig.) I'll put the log and then the source between readmore tags:
2021/10/10 19:11:13 INFO ./3.mp.pl
2021/10/10 19:11:13 INFO 817 meters in the 'Ho on 2021-10-14T03:22:31
+(1634156551 seconds unix-epoch) timezone: +0700 (lat: 43.61, lon: -11
+6.2)
2021/10/10 19:11:13 INFO Moon age: 8.12733852952393 days
2021/10/10 19:11:13 INFO Moon phase: 27.5 % of cycle (birth-to-death)
2021/10/10 19:11:13 INFO Moon's illuminated fraction: 57.9 % of full d
+isc
2021/10/10 19:11:13 INFO Object Azimuth Elevation
2021/10/10 19:11:13 INFO Venus 149.440165717993 15.727434443
+4415
2021/10/10 19:11:13 INFO Jupiter 85.3855790615229 -27.009312
+5350183
2021/10/10 19:11:13 INFO Moon 107.660568864375 -18.129253458
+383
2021/10/10 19:11:13 INFO Saturn 99.431806664097 -18.48745351
+68097
2021/10/10 19:11:13 INFO 817 meters on the Scylla on 2021-10-14T03:22:
+31 (1634170951 seconds unix-epoch) timezone: Africa/Nairobi (lat: 15.
+6325, lon: 38.245833)
2021/10/10 19:11:13 INFO Moon age: 8.30043411740843 days
2021/10/10 19:11:13 INFO Moon phase: 28.1 % of cycle (birth-to-death)
2021/10/10 19:11:13 INFO Moon's illuminated fraction: 59.7 % of full d
+isc
2021/10/10 19:11:13 INFO Object Azimuth Elevation
2021/10/10 19:11:13 INFO Venus 168.793996164728 -81.01106162
+58686
2021/10/10 19:11:13 INFO Jupiter 258.080321870357 -14.857584
+1846033
2021/10/10 19:11:13 INFO Moon 251.270738258432 -35.268506488
+5712
2021/10/10 19:11:13 INFO Saturn 256.410482564197 -30.2637811
+706649
2021/10/10 19:11:13 INFO 817 meters in Antipo' 'Ho on 2021-10-14T03:22
+:31 (1634196151 seconds unix-epoch) timezone: -0400 (lat: -43.61, lon
+: 63.8)
2021/10/10 19:11:13 INFO Moon age: 8.60197696037111 days
2021/10/10 19:11:13 INFO Moon phase: 29.1 % of cycle (birth-to-death)
2021/10/10 19:11:13 INFO Moon's illuminated fraction: 62.8 % of full d
+isc
2021/10/10 19:11:13 INFO Object Azimuth Elevation
2021/10/10 19:11:13 INFO Venus 79.6274128242256 46.927926715
+5178
2021/10/10 19:11:13 INFO Jupiter 127.915109889761 -14.257597
+1913744
2021/10/10 19:11:13 INFO Moon 121.660606406209 0.26418104014
+4833
2021/10/10 19:11:13 INFO Saturn 118.937176589619 -1.57596843
+956774
2021/10/10 19:11:13 INFO 817 meters at Antipodlean Scylla on 2021-10-1
+4T03:22:31 (1634145751 seconds unix-epoch) timezone: +1000 (lat: -15.
+6325, lon: -141)
2021/10/10 19:11:13 INFO Moon age: 7.99713693338972 days
2021/10/10 19:11:13 INFO Moon phase: 27.1 % of cycle (birth-to-death)
2021/10/10 19:11:13 INFO Moon's illuminated fraction: 56.5 % of full d
+isc
2021/10/10 19:11:13 INFO Object Azimuth Elevation
2021/10/10 19:11:13 INFO Venus 116.80202915781 -4.3309268944
+6216
2021/10/10 19:11:13 INFO Jupiter 185.633623950117 -59.076854
+3475159
2021/10/10 19:11:13 INFO Moon 152.685924835122 -45.404404422
+7405
2021/10/10 19:11:13 INFO Saturn 160.016969111463 -52.8842049
+328507
Source:
#!/usr/bin/perl
use v5.030;
use warnings;
#use Time::Piece; using DateTime instead
use Astro::Coord::ECI::Utils 'deg2rad';
use Astro::Coords;
use Astro::MoonPhase;
use Astro::Telescope;
use DateTime;
use DateTime::Format::ISO8601;
use DateTime::TimeZone;
use Data::Dumper;
use Log::Log4perl;
use Try::Tiny;
######
# Calculate the moon phase of an event in time.
# Required is the date (time defaults to 00:00:01) of the event
# The moon-phase calculator does not need a location
# since moon phase is the same across the planet (more-or-less)
# with the usual antipodean side-effects
# However, by specifying a timezone or even coordinates of the
# event conversion of event's time to UTC is more accurate
# (else UTC time is assumed)
# author: bliako, modified by aldebaran
# date: 2021-10-10
######
my $debug = 0;
my $time_str = "03:22:31";
my $alt = 817;
my $date_str = "2021-10-14";
my @events = (
# {
# # example event specification
# "name" => "a name for reference, required",
# "date" => "date of the event in YYYY-MM-DD",
# "time" => "optional time as hh:mm:ss, default is 00:00:01",
# #specify optional location using one of these for calculating
# #epoch which uses UTC time,
# #otherwise, UTC timezone will be assumed for event's time:
# "timezone" => "standard timezone name, e.g. America/Havana",
# "location" => "cuba",
# "location" => {lon=>-81.137633, lat=>22.17927},
# },
{
"name" => "$alt meters in the 'Ho",
"date" => $date_str,
"time" => $time_str,
"location" => { lon => -116.2, lat => 43.61 },
},
{
"name" => "$alt meters on the Scylla",
"date" => $date_str,
"time" => $time_str,
"location" => { lon => 38.245833, lat => 15.6325 },
},
{
"name" => "$alt meters in Antipo' 'Ho",
"date" => $date_str,
"time" => $time_str,
"location" => { lon => 63.8, lat => -43.61 },
},
{
"name" => "$alt meters at Antipodlean Scylla",
"date" => $date_str,
"time" => $time_str,
"location" => { lon => -141, lat => -15.6325 },
},
);
my $file = '/home/hogan/Documents/hogan/logs/3.log4perl.txt';
# unlink $file or warn "Could not unlink $file: $!";
my $log_conf4 = "/home/hogan/Documents/hogan/logs/conf_files/3.conf";
Log::Log4perl::init($log_conf4); #info
my $logger = Log::Log4perl->get_logger();
$logger->info("$0");
## event loop
for my $event (@events) {
my $epoch = parse_event($event);
$logger->info( event2str($event) );
my ( $MoonPhase, $MoonIllum, $MoonAge, $MoonDist, $MoonAng, $SunDist
+,
$SunAng ) = phase($epoch);
$logger->info("Moon age: $MoonAge days");
$logger->info( "Moon phase: "
. sprintf( "%.1f", 100.0 * $MoonPhase )
. " % of cycle (birth-to-death)" );
$logger->info( "Moon's illuminated fraction: ",
sprintf( "%.1f", 100.0 * $MoonIllum ) . " % of full disc" );
$logger->info("Object\tAzimuth\t\tElevation");
for my $name (qw/Venus Jupiter Moon Saturn/) {
my $planet = Astro::Coords->new( planet => $name );
# use DateTime
my $date = DateTime->from_epoch( epoch => $epoch, time_zone => 'UT
+C' );
$planet->datetime($date);
$planet->telescope(
Astro::Telescope->new(
Name => $event->{name},
Long => deg2rad( $event->{location}->{lon} ),
Lat => deg2rad( $event->{location}->{lat} ),
Alt => $alt, #meters above sea level
)
);
my $az = $planet->az( format => 'deg' );
my $el = $planet->el( format => 'deg' );
$logger->info("$name\t$az\t\t$el");
}
## end planets loop
}
## end event loop
sub event2str {
my $event = shift;
if ( !exists $event->{_is_parsed} ) {
warn "event has not been parsed, just dumping it...";
print Dump($event);
}
my $str =
$event->{name} . " on "
. $event->{datetime} . " ("
. $event->{datetime}->epoch
. " seconds unix-epoch)"
. " timezone: "
. $event->{datetime}->time_zone->name;
if ( exists $event->{location} ) {
if ( ref( $event->{location} ) eq 'HASH' ) {
$str .=
" (lat: "
. $event->{location}->{lat}
. ", lon: "
. $event->{location}->{lon} . ")";
}
else { $str .= "(" . $event->{location} . ")" }
}
return $str;
}
sub parse_event {
my $event = shift;
if ( !exists $event->{date} ) { die "date field is missing from even
+t." }
my $datestr = $event->{date};
die "event does not have a 'name' field, please specify one, anythin
+g really."
unless exists $event->{name};
my $timestr = "00:00:01";
if ( exists $event->{time} ) {
$timestr = $event->{time};
print "event2epoch(): setting time to '$timestr' ...\n"
if $debug > 0;
die "time '$timestr' is not valid, it must be in the form 'hh:mm:s
+s'."
unless $timestr =~ /^\d{2}:\d{2}:\d{2}$/;
}
else { $event->{time} = $timestr }
my $isostr = $datestr . 'T' . $timestr;
my $dt = DateTime::Format::ISO8601->parse_datetime($isostr);
die "failed to parse date '$isostr', check date and time fields."
unless defined $dt;
$event->{datetime} = $dt;
my $tzstr = 'UTC';
if ( exists $event->{timezone} ) {
$tzstr = $event->{timezone};
print
"event2epoch(): found a timezone via 'timezone' field as '$tzstr' (tha
+t does not mean it is valid) ...\n"
if $debug > 0;
}
elsif ( exists $event->{location} ) {
my $loc = $event->{location};
if ( ( ref($loc) eq '' ) && ( $loc =~ /^[a-zA-Z]$/ ) ) {
# we have a location string
my @alltzs = DateTime::TimeZone->all_names;
my $tzstr;
for (@alltzs) {
if ( $_ =~ /$loc/i ) { $tzstr = $_; last }
}
die
"event's location can not be converted to a timezone, consider specify
+ing the 'timezone' directly or setting 'location' coordinates with: \
+[lat,lon\]."
unless $tzstr;
print
"event2epoch(): setting timezone via 'location' name to '$timestr' ...
+\n"
if $debug > 0;
}
elsif ( ( ref($loc) eq 'HASH' )
&& ( exists $loc->{lat} )
&& ( exists $loc->{lon} ) )
{
# we have a [lat,lon] array for location
require Geo::Location::TimeZone;
my $gltzobj = Geo::Location::TimeZone->new();
$tzstr = $gltzobj->lookup( lat => $loc->{lat}, lon => $loc->{lon
+} );
if ( !$tzstr ) {
die "timezone lookup from location coordinates lat:"
. $loc->{lat}
. ", lon:"
. $loc->{lon}
. " has failed.";
}
print "event2epoch(): setting timezone via 'location' coordinate
+s lat:"
. $loc->{lat}
. ", lon:"
. $loc->{lon}
. " ...\n"
if $debug > 0;
}
}
if ($tzstr) {
print "event2epoch(): deduced timezone to '$tzstr' and setting it
+...\n"
if $debug > 0;
try {
$dt->set_time_zone($tzstr)
}
catch {
die "$_\n failed to set the timezone '$tzstr', is it valid?"
}
}
$event->{_is_parsed} = 1;
$event->{epoch} = $dt->epoch;
return $event->{epoch};
}
__END__
One thing I noticed is that these data are very sensitive to altitude of the defined observer. A person at 817 meters above the Scylla would have a much better view of rising and setting planets. Is there any way to figure out what a reasonable guesstimate is of altitude given latitude and longitude?
How long does the moon's transit from Venus to Jupiter take?
How can I determine that a priori? I know that I can bound the value in DateTime with output from the original post. Can one loop over this interval with the methods of DateTime adding the duration of a second and then checking values. A month isn't a lot of seconds for a computer.
Re^4: Moon phase on historical events
by bliako (Monsignor) on Oct 11, 2021 at 11:51 UTC
|
my $dt = DateTime->new(
year => 2021,
month => 4,
day => 5,
hour => 2,
time_zone => 'Africa/Nairobi',
);
# or, create a DateTime object from an ISO timestring
my $isostr = '2021-10-11T11:13:57';
my $dt = DateTime::Format::ISO8601->parse_datetime($isostr);
# add a second to what $dt currently holds
$dt->add(seconds => 1);
Regarding your other questions, I have no clue about celestial mechanics. Nonetheless I have whipped up a Perl sub to get you the elevation given coordinates. It uses a site which I am not sure if they would like people using their services in this way. So with that in mind:
# usage:
# my $elevation = get_elevation_from_coordinates(15.6325, 38.245833, 0
+);
sub get_elevation_from_coordinates {
my ($lat, $lon, $debug) = @_;
$debug //= 0;
my $ua = LWP::UserAgent->new(
agent => 'Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100
+101 Firefox/78.0',
);
my $response;
my $payload =
'latitude='.$lat
.'&longitude='.$lon
.'&application_max_assets_mtime=1559625591'
;
my $payloadlen = length($payload);
# this request was translated from Curl command-line
# by [Corion]'s https://corion.net/curl2lwp.psgi
my $req = HTTP::Request->new(
'POST' => 'https://www.mapcoordinates.net/admin/component/edit
+/Vpc_MapCoordinates_Advanced_GoogleMapCoords_Component/Component/json
+-get-elevation',
[
'Connection' => 'keep-alive',
'Accept' => '*/*',
'Accept-Encoding' => 'gzip, x-gzip, deflate, x-bzip2, bzip2',
'Accept-Language' => 'en-US,en;q=0.5',
# 'Host' => 'www.mapcoordinates.net:443',
'Referer' => 'https://www.mapcoordinates.net/en',
'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64; rv:78.0)
+Gecko/20100101 Firefox/78.0',
'Content-Length' => $payloadlen,
'Content-Type' => 'application/x-www-form-urlencoded; charse
+t=UTF-8',
'DNT' => '1',
'Origin' => 'https://www.mapcoordinates.net',
'X-Requested-With' => 'XMLHttpRequest'
],
$payload
);
die "call to HTTP::Request has failed" unless $req;
if( $debug > 0 ){ print "$0 : $payload\n$0 : sending above payload
+, of $payloadlen bytes...\n" }
$response = $ua->request($req);
die "Error fetching: ".$response->status_line
unless $response->is_success;
my $content = $response->decoded_content;
my $data = Data::Roundtrip::json2perl($content);
die "failed to parse received data:\n$content\n"
unless exists $data->{'elevation'};
return $data->{'elevation'};
}
bw, bliako
| [reply] [Watch: Dir/Any] [d/l] [select] |
Re^4: Moon phase on historical events
by Anonymous Monk on Feb 11, 2022 at 07:26 UTC
|
| [reply] [Watch: Dir/Any] |
|
use Geo::WebService::Elevation::USGS;
use Data::Dumper;
my $eq = Geo::WebService::Elevation::USGS->new(
timeout => 60,
);
# white house
my $x = $eq->elevation(38.91205168958467, -77.03355236501928);
print Dumper($x);
# scilla sicily
$x = $eq->elevation(38.17378844699463, 15.83642789839883);
print Dumper($x);
$VAR1 = {
'Units' => 'Feet',
'Data_Source' => '3DEP 1/3 arc-second',
'y' => '38.9120516895847',
'Elevation' => '96.95',
'x' => '-77.0335523650193'
};
$VAR1 = {
'y' => '38.1737884469946',
'x' => '15.8364278983988',
'Elevation' => '-1000000',
'Units' => 'Feet',
'Data_Source' => '3DEP 1/3 arc-second'
};
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
fritz@hogan-Lenovo-IdeaPad-S145-15IWL:~/Documents$ ./7.mp.pl
Subroutine get_logger redefined at ./7.mp.pl line 41.
INFO: ./7.mp.pl
in new scylla on 2022-02-18T03:22:31 (1645150951 seconds unix-epoch) t
+imezone: Europe/Rome (lat: 38.1737884469946, lon: 15.8364278983988)
Moon age: 16.1131124830837 days
Moon phase: 54.6 % of cycle (birth-to-death)
Moon's illuminated fraction: 98.0 % of full disc
important moon phases around the event:
New Moon = Mon Jan 31 22:49:10 2022
First quarter = Tue Feb 8 06:51:53 2022
Full moon = Wed Feb 16 09:59:41 2022
Last quarter = Wed Feb 23 15:34:32 2022
New Moon = Wed Mar 2 10:38:16 2022
end event.
INFO: return from the google is 1291 meters
INFO: in new scylla on 2022-02-18T03:22:31 (1645150951 seconds unix-ep
+och) timezone: Europe/Rome (lat: 38.1737884469946, lon: 15.8364278983
+988) at height 1293 meters
INFO: Object Azimuth Elevation
INFO: Venus 103.996877720637 -9.60439269992599
INFO: Jupiter 57.162019344654 -45.6099678242824
INFO: Moon 232.083188637894 50.0250955497636
INFO: Saturn 84.3881395776426 -34.0613320748201
fritz@hogan-Lenovo-IdeaPad-S145-15IWL:~/Documents$ cat 7.mp.pl
#!/usr/bin/perl
use v5.030; # strictness implied
use warnings;
use feature qw[ signatures ];
no warnings qw[ experimental::signatures ];
use Astro::Coord::ECI::Utils 'deg2rad';
use Astro::Coords;
use Astro::MoonPhase;
use Astro::Telescope;
use Data::Dumper;
use DateTime;
use DateTime::Format::ISO8601;
use DateTime::TimeZone;
use Log::Log4perl;
use Try::Tiny;
our $debug = 0;
my $time_str = "03:22:31";
my $alt = 0;
my $date_str = "2022-02-18";
my @events = (
{
"name" => "in new scylla",
"date" => $date_str,
"time" => $time_str,
"location" => { lon => 15.83642789839883, lat => 38.17378844699463
+ },
},
);
# Not wanting to divine the configuration file for Log::Log4perl, modu
+le used in
# the query. Better for SSCCE considerations. thx parv
{
package Log::Log4perl;
sub get_logger ($pkg) { return bless [], $pkg; }
sub show (@arg) { warn @arg, "\n"; }
sub debug ( $ignore, @rest ) { show( 'DEBUG: ', @rest ); }
sub info ( $ignore, @rest ) { show( 'INFO: ', @rest ); }
sub warn ( $ignore, @rest ) { show( 'WARNING: ', @rest ); }
sub error ( $ignore, @rest ) { die 'ERROR: ', @rest, "\n"; }
}
my $logger = Log::Log4perl->get_logger();
$logger->info("$0");
## event loop
for my $event (@events) {
my $epoch = parse_event($event);
print event2str($event) . "\n";
my ( $MoonPhase,
$MoonIllum,
$MoonAge,
$MoonDist,
$MoonAng,
$SunDist,
$SunAng
) = phase($epoch);
print "Moon age: $MoonAge days\n";
print "Moon phase: ".sprintf("%.1f", 100.0*$MoonPhase)." % of cycl
+e (birth-to-death)\n";
print "Moon's illuminated fraction: ",sprintf("%.1f", 100.0*$MoonI
+llum)." % of full disc\n";
print "important moon phases around the event:\n";
my @phases = phasehunt($epoch);
print " New Moon = ", scalar(localtime($phases[0])), "\n";
print " First quarter = ", scalar(localtime($phases[1])), "\n";
print " Full moon = ", scalar(localtime($phases[2])), "\n";
print " Last quarter = ", scalar(localtime($phases[3])), "\n";
print " New Moon = ", scalar(localtime($phases[4])), "\n";
print "end event.\n\n";
## determine altitude
# usage:
die unless exists $event->{location}; # restriction
my $return = get_elevation_from_coordinates( $event->{location}->{la
+t},
$event->{location}->{lon}, $debug );
$logger->info("return from the google is $return meters");
my $observer = $return + 2; #(most people stand)
$logger->info( event2str($event) . " at height $observer meters" );
$logger->info("Object\tAzimuth\t\tElevation");
for my $name (qw/Venus Jupiter Moon Saturn/) {
my $planet = Astro::Coords->new( planet => $name );
# use DateTime
my $date = DateTime->from_epoch( epoch => $epoch, time_zone => 'UT
+C' );
$planet->datetime($date);
$planet->telescope(
Astro::Telescope->new(
Name => $event->{name},
Long => deg2rad( $event->{location}->{lon} ),
Lat => deg2rad( $event->{location}->{lat} ),
Alt => $observer, #meters above
+sea level
)
);
my $az = $planet->az( format => 'deg' );
my $el = $planet->el( format => 'deg' );
$logger->info("$name\t$az\t\t$el");
}
## end planets loop
}
## end event loop
sub event2str {
my $event = shift;
if ( !exists $event->{_is_parsed} ) {
warn "event has not been parsed, just dumping it...";
print Dump($event);
}
my $str =
$event->{name} . " on "
. $event->{datetime} . " ("
. $event->{datetime}->epoch
. " seconds unix-epoch)"
. " timezone: "
. $event->{datetime}->time_zone->name;
if ( exists $event->{location} ) {
if ( ref( $event->{location} ) eq 'HASH' ) {
$str .=
" (lat: "
. $event->{location}->{lat}
. ", lon: "
. $event->{location}->{lon} . ")";
}
else { $str .= "(" . $event->{location} . ")" }
}
return $str;
}
sub parse_event {
my $event = shift;
$debug //= 0;
if ( !exists $event->{date} ) { die "date field is missing from even
+t." }
my $datestr = $event->{date};
die "event does not have a 'name' field, please specify one, anythin
+g really."
unless exists $event->{name};
my $timestr = "00:00:01";
if ( exists $event->{time} ) {
$timestr = $event->{time};
print "event2epoch(): setting time to '$timestr' ...\n"
if $debug > 0;
die "time '$timestr' is not valid, it must be in the form 'hh:mm:s
+s'."
unless $timestr =~ /^\d{2}:\d{2}:\d{2}$/;
}
else { $event->{time} = $timestr }
my $isostr = $datestr . 'T' . $timestr;
my $dt = DateTime::Format::ISO8601->parse_datetime($isostr);
die "failed to parse date '$isostr', check date and time fields."
unless defined $dt;
$event->{datetime} = $dt;
my $tzstr = 'UTC';
if ( exists $event->{timezone} ) {
$tzstr = $event->{timezone};
print
"event2epoch(): found a timezone via 'timezone' field as '$tzstr' (tha
+t does not mean it is valid) ...\n"
if $debug > 0;
}
elsif ( exists $event->{location} ) {
my $loc = $event->{location};
if ( ( ref($loc) eq '' ) && ( $loc =~ /^[a-zA-Z]$/ ) ) {
# we have a location string
my @alltzs = DateTime::TimeZone->all_names;
my $tzstr;
for (@alltzs) {
if ( $_ =~ /$loc/i ) { $tzstr = $_; last }
}
die
"event's location can not be converted to a timezone, consider specify
+ing the 'timezone' directly or setting 'location' coordinates with: \
+[lat,lon\]."
unless $tzstr;
print
"event2epoch(): setting timezone via 'location' name to '$timestr' ...
+\n"
if $debug > 0;
}
elsif ( ( ref($loc) eq 'HASH' )
&& ( exists $loc->{lat} )
&& ( exists $loc->{lon} ) )
{
# we have a [lat,lon] array for location
require Geo::Location::TimeZone;
my $gltzobj = Geo::Location::TimeZone->new();
$tzstr = $gltzobj->lookup( lat => $loc->{lat}, lon => $loc->{lon
+} );
if ( !$tzstr ) {
die "timezone lookup from location coordinates lat:"
. $loc->{lat}
. ", lon:"
. $loc->{lon}
. " has failed.";
}
print "event2epoch(): setting timezone via 'location' coordinate
+s lat:"
. $loc->{lat}
. ", lon:"
. $loc->{lon}
. " ...\n"
if $debug > 0;
}
}
if ($tzstr) {
print "event2epoch(): deduced timezone to '$tzstr' and setting it
+...\n"
if $debug > 0;
try {
$dt->set_time_zone($tzstr)
}
catch {
die "$_\n failed to set the timezone '$tzstr', is it valid?"
}
}
$event->{_is_parsed} = 1;
$event->{epoch} = $dt->epoch;
return $event->{epoch};
}
sub get_elevation_from_coordinates {
my ( $lat, $lon, $debug ) = @_;
use LWP::UserAgent;
use HTTP::Request;
use Data::Roundtrip;
$debug //= 0;
my $ua = LWP::UserAgent->new( agent =>
'Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox
+/78.0', );
my $response;
my $payload =
'latitude='
. $lat
. '&longitude='
. $lon
. '&application_max_assets_mtime=1559625591';
my $payloadlen = length($payload);
# this request was translated from Curl command-line
# by [Corion]'s https://corion.net/curl2lwp.psgi
my $req = HTTP::Request->new(
'POST' =>
'https://www.mapcoordinates.net/admin/component/edit/Vpc_MapCoordinate
+s_Advanced_GoogleMapCoords_Component/Component/json-get-elevation',
[
'Connection' => 'keep-alive',
'Accept' => '*/*',
'Accept-Encoding' => 'gzip, x-gzip, deflate, x-bzip2, bzip2',
'Accept-Language' => 'en-US,en;q=0.5',
# 'Host' => 'www.mapcoordinates.net:443',
'Referer' => 'https://www.mapcoordinates.net/en',
'User-Agent' =>
'Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firef
+ox/78.0',
'Content-Length' => $payloadlen,
'Content-Type' => 'application/x-www-form-urlencoded; charse
+t=UTF-8',
'DNT' => '1',
'Origin' => 'https://www.mapcoordinates.net',
'X-Requested-With' => 'XMLHttpRequest'
],
$payload
);
die "call to HTTP::Request has failed" unless $req;
if ( $debug > 0 ) {
$logger->debug(
"$0 : $payload\n$0 : sending above payload, of $payloadlen bytes
+...");
}
$response = $ua->request($req);
die "Error fetching: " . $response->status_line
unless $response->is_success;
my $content = $response->decoded_content;
my $data = Data::Roundtrip::json2perl($content);
die "failed to parse received data:\n$content\n"
unless exists $data->{'elevation'};
return $data->{'elevation'};
}
__END__
fritz@hogan-Lenovo-IdeaPad-S145-15IWL:~/Documents$
My units are meters here from what we did before, but Americans won't understand what doesn't comport with their religion: football. | [reply] [Watch: Dir/Any] [d/l] |
|
|