astrology tool perl script

friday may 01 2015

 

A perl script that asks for the positions of two planetary objects and what zodiac sign they are in then calculates and returns aspect information.
This script automatically documents every query.

astrology perl script

#!/usr/bin/perl
use strict;
use warnings;

use Geo::Coordinates::DecimalDegrees;

# astrology_tool.pl

# the degree symbol
my $dgs .= qq/\xB0/;

my $i; # counter
my $c; # counter
my $input;

my @objectnames = qw(Sun Moon Mercury Venus Mars Jupiter Saturn Uranus Neptune Pluto Chiron Lilith North-Node South-Node Ascendant Midheaven);

my @zodiacname = qw(Aries Taurus Gemini Cancer Leo Virgo Libra Scorpio Sagittarius Capricorn Aquarius Pisces);
my @zodiacdegree = qw(0 30 60 90 120 150 180 210 240 270 300 330 360);
my @zodiacruler = qw(Mars Venus Mercury Moon Sun Mercury Venus Pluto Jupiter Saturn Uranus Neptune);
my @zodiacexalted = qw(Sun Moon x Jupiter x x Saturn x x Mars x Venus);
my @zodiacdetriment = qw(Venus Mars Jupiter Saturn Saturn Jupiter Mars Venus Mercury Moon Sun Mercury);
my @zodiacfall = qw(Saturn x x Mars x Venus Sun Moon x Jupiter x x);
my @zodiacquality = qw(Cardinal Fixed Mutable Cardinal Fixed Mutable Cardinal Fixed Mutable Cardinal Fixed Mutable);
my @zodiacelement = qw(Fire Earth Air Water Fire Earth Air Water Fire Earth Air Water);
my @zodiacpolarity = qw(Yang+M Yin-F Yang+M Yin-F Yang+M Yin-F Yang+M Yin-F Yang+M Yin-F Yang+M Yin-F);

my @aspectnames = qw(Conjunct Semisextile Semiquintile Novile Semisquare Septile Sextile Quintile Binovile Square Biseptile Trine Sesquiquadrate Biquintile Inconjunct Triseptile Quatronovile Quindecile Opposite);
my @aspectdegree = qw(0 30 36 40 45 51.4285 60 72 80 90 102.857 120 135 144 150 154.285 160 165 180);

my $objectname1;
my $zodiacname1;
my $degrees1;
my $minutes1;
my $minutes1rounded;
my $seconds1;
my $seconds1rounded;
my $angle1;
my $angle3601;

my $objectname2;
my $zodiacname2;
my $degrees2;
my $minutes2;
my $minutes2rounded;
my $seconds2;
my $seconds2rounded;
my $angle2;
my $angle3602;

my $distance;
my $distancefar;
my $aspect;
my $orb;
my $midpoint;
my $midpointdegree;
my $midpointminute;
my $midpointminuterounded;
my $zodiacmidpointnear;
my $zodiacmidpointneardegree;
my $zodiacmidpointnearminute;
my $zodiacmidpointnearminuterounded;
my $zodiacmidpointfar;
my $zodiacmidpointfardegree;
my $zodiacmidpointfarminute;
my $zodiacmidpointfarminuterounded;

my $tmpvar;

my @dataset1;
my @dataset2;
my @dataset3;
my @dataset4;
my @dataset5;
my @dataset6;

my $recordfile = "recordfile.txt";

###############################################

get_dataset1();

get_dataset2();

# print dataset1
# example $decimal_degrees = dms2decimal($degrees, $minutes, $seconds);
$angle1 = dms2decimal($degrees1, $minutes1, $seconds1);
# previous method to get decimal degrees # $angle1 = $degrees1 + ($minutes1*1/60) + ($seconds1*1/60*1/60);
print "\n1 : $objectname1 $degrees1 $dgs $zodiacname1 $minutes1 \' $seconds1 \"\n";
# print "decimal angle: $angle1\n";
# convert planet position to 360 degree format
foreach $i (0 .. $#zodiacname) {
# print "$i - $zodiacname[$i] - $zodiacdegree[$i]\n";
if ( $zodiacname1 eq $zodiacname[$i] ) {
# print "starting degree of $zodiacname1 is $zodiacdegree[$i] $dgs\n";
$angle3601 = $zodiacdegree[$i] + $angle1;
# print "distance from 0 $dgs Aries : $angle3601 $dgs\n";
($degrees1, $minutes1, $seconds1) = decimal2dms($angle3601);
$seconds1rounded = int($seconds1+0.5);
print "distance from 0 $dgs Aries : $degrees1 $dgs $minutes1 \' $seconds1rounded \"\n";
if ( $objectname1 eq $zodiacruler[$i] ) {
print "$zodiacname1 : Ruler : $zodiacruler[$i]\n";
}
if ( $objectname1 eq $zodiacexalted[$i] ) {
print "$zodiacname1 : Exalted : $zodiacexalted[$i]\n";
}
if ( $objectname1 eq $zodiacdetriment[$i] ) {
print "$zodiacname1 : Detriment : $zodiacdetriment[$i]\n";
}
if ( $objectname1 eq $zodiacfall[$i] ) {
print "$zodiacname1 : Fall : $zodiacfall[$i]\n";
}
print "$zodiacname1 : $zodiacquality[$i] : $zodiacelement[$i] : $zodiacpolarity[$i]\n";
push (@dataset1, $angle3601);
}
}

# print dataset2
# example $decimal_degrees = dms2decimal($degrees, $minutes, $seconds);
$angle2 = dms2decimal($degrees2, $minutes2, $seconds2);
# previous method to get decimal degrees # $angle2 = $degrees2 + ($minutes2*1/60) + ($seconds2*1/60*1/60);
print "\n2 : $objectname2 $degrees2 $dgs $zodiacname2 $minutes2 \' $seconds2 \"\n";
# print "decimal angle: $angle2\n";
# convert planet position to 360 degree format
foreach $i (0 .. $#zodiacname) {
# print "$i - $zodiacname[$i] - $zodiacdegree[$i]\n";
if ( $zodiacname2 eq $zodiacname[$i] ) {
# print "starting degree of $zodiacname2 is $zodiacdegree[$i] $dgs\n";
$angle3602 = $zodiacdegree[$i] + $angle2;
# print "distance from 0 $dgs Aries : $angle3602 $dgs\n";
($degrees2, $minutes2, $seconds2) = decimal2dms($angle3602);
$seconds2rounded = int($seconds2+0.5);
print "distance from 0 $dgs Aries : $degrees2 $dgs $minutes2 \' $seconds2rounded \"\n";
if ( $objectname2 eq $zodiacruler[$i] ) {
print "$zodiacname2 : Ruler : $zodiacruler[$i]\n";
}
if ( $objectname2 eq $zodiacexalted[$i] ) {
print "$zodiacname2 : Exalted : $zodiacexalted[$i]\n";
}
if ( $objectname2 eq $zodiacdetriment[$i] ) {
print "$zodiacname2 : Detriment : $zodiacdetriment[$i]\n";
}
if ( $objectname2 eq $zodiacfall[$i] ) {
print "$zodiacname2 : Fall : $zodiacfall[$i]\n";
}
print "$zodiacname2 : $zodiacquality[$i] : $zodiacelement[$i] : $zodiacpolarity[$i]\n";
push (@dataset2, $angle3602);
}
}

# results: print distances in degrees, aspects and midpoints

# it needs a positive distance number between the objects # using decimal degrees here
if ( $angle3602 > $angle3601 ) {
$distance = $angle3602 - $angle3601;
}
else {
if ( $angle3601 > $angle3602 ) {
$distance = $angle3601 - $angle3602;
}
}

$distancefar = 360 - $distance;

# print decimal distance # print "\nDistance $objectname1 \- $objectname2 : $distance $dgs\n";
# find aspect names and orb
# convert decimal distance to distance in degrees minutes
# finding aspects can only be done using degrees or integers, not decimals
# example ($degrees, $minutes) = decimal2dm($decimal_degrees);
($degrees1, $minutes1) = decimal2dm($distance);
$minutes1rounded = int($minutes1+0.5);
print "\nDistance $objectname1 \- $objectname2 : $degrees1 $dgs $minutes1rounded \'\n";
push (@dataset3, $distance);
for $c (-10 .. 10) {
$orb = $degrees1 + $c;
# print "orb $orb\n";
for $i (0 .. $#aspectdegree) {
if ($orb == $aspectdegree[$i]) {
$tmpvar = $aspectnames[$i];
print "Aspect : $aspectnames[$i] orb $c $dgs\n";
push (@dataset3, $distance, $tmpvar, $c, $distancefar);
}
}
}

# print decimal distance far # print "distance $objectname2 \- $objectname1 : $distancefar $dgs\n";
# find aspect names and orb
# convert decimal distance to distance in degrees minutes
# finding aspects can only be done using degrees or integers, not decimals
# example ($degrees, $minutes) = decimal2dm($decimal_degrees);
($degrees2, $minutes2) = decimal2dm($distancefar);
$minutes2rounded = int($minutes2+0.5);
print "\ndistance $objectname2 \- $objectname1 : $degrees2 $dgs $minutes2rounded \'\n";
push (@dataset4, $distancefar);
for $c (-10 .. 10) {
$orb = $degrees2 + $c;
# print "orb $orb\n";
for $i (0 .. $#aspectdegree) {
if ($orb == $aspectdegree[$i]) {
$tmpvar = $aspectnames[$i];
print "aspect : $aspectnames[$i] orb $c $dgs\n";
push (@dataset4, $distance, $tmpvar, $c, $distancefar);
}
}
}

# midpoint near
$midpoint = ($angle3601 + $angle3602) / 2;
# print decimal midpoint # print "\nmidpoint near from 0 $dgs Aries : $midpoint $dgs\n";
($midpointdegree, $midpointminute) = decimal2dm($midpoint);
$midpointminuterounded = int($midpointminute+0.5);
print "\nmidpoint near from 0 $dgs Aries : $midpointdegree $dgs $midpointminuterounded \'\n";
foreach $i (0 .. $#zodiacdegree) {
if ($midpoint >= $zodiacdegree[$i] and $midpoint <= $zodiacdegree[$i+1]) {
$zodiacmidpointnear = $midpoint - $zodiacdegree[$i];
# print decimal print "Midpoint near $objectname1 \/ $objectname2 : $zodiacmidpointnear $dgs $zodiacname[$i]\n";
($zodiacmidpointneardegree, $zodiacmidpointnearminute) = decimal2dm($zodiacmidpointnear);
$zodiacmidpointnearminuterounded = int($zodiacmidpointnearminute+0.5);
print "Midpoint near $objectname1 \/ $objectname2 : $zodiacmidpointneardegree $dgs $zodiacmidpointnearminuterounded \' $zodiacname[$i]\n";
$tmpvar = $zodiacname[$i];
push (@dataset5, $midpoint, $zodiacmidpointnear, $tmpvar);
}
}

# midpoint far
$zodiacmidpointfar = $midpoint + 180;
if ( $zodiacmidpointfar > 360 ) {
$zodiacmidpointfar = $zodiacmidpointfar - 360;
}
# print decimal # print "\nmidpoint far from 0 $dgs Aries : $zodiacmidpointfar $dgs\n";
($zodiacmidpointfardegree, $zodiacmidpointfarminute) = decimal2dm($zodiacmidpointfar);
$zodiacmidpointfarminuterounded = int($zodiacmidpointfarminute+0.5);
print "\nmidpoint far from 0 $dgs Aries : $zodiacmidpointfardegree $dgs $zodiacmidpointfarminuterounded \'\n";
push (@dataset6, $zodiacmidpointfar);
foreach $i (0 .. $#zodiacdegree) {
if ($zodiacmidpointfar >= $zodiacdegree[$i] and $zodiacmidpointfar <= $zodiacdegree[$i+1] ) {
$zodiacmidpointfar = $zodiacmidpointfar - $zodiacdegree[$i];
# print decimal # print "Midpoint far $objectname1 \/ $objectname2 : $zodiacmidpointfar $dgs $zodiacname[$i]\n";
($zodiacmidpointfardegree, $zodiacmidpointfarminute) = decimal2dm($zodiacmidpointfar);
$zodiacmidpointfarminuterounded = int($zodiacmidpointfarminute+0.5);
print "Midpoint far $objectname2 \/ $objectname1 : $zodiacmidpointfardegree $dgs $zodiacmidpointfarminuterounded \' $zodiacname[$i]\n";
$tmpvar = $zodiacname[$i];
push (@dataset6, $zodiacmidpointfar, $tmpvar);
}
}

# print data to recordfile.txt # @dataset1 # @dataset2
open my $fh, ">>", $recordfile or die("could not open file. $!");
print $fh "#\n";
print $fh "1 : @dataset1\n2 : @dataset2\n3 : @dataset3\n4 : @dataset4\n5 : @dataset5\n6 : @dataset6\n";
# print $fh "#\n";
close $fh;

print "\nend of program\n";
exit 0;

###############################################

sub get_dataset1 {
print "\nEnter 1st Objectname,$dgs,\',\",Zodiacname : ";
$input = ;
chomp $input;

@dataset1 = split(',',$input);

# foreach $i (0 .. $#dataset1) {
# print "$i - $dataset1[$i]\n";
# }

if ( $i = grep { $_ eq $dataset1[0] } @objectnames ) {
$objectname1 = $dataset1[0];
}
else {
get_dataset1();
}

if ( $dataset1[1] >= 0 and $dataset1[1] <= 29 ) {
$degrees1 = $dataset1[1];
}
else {
get_dataset1();
}

if ( $dataset1[2] >= 0 and $dataset1[2] <= 59 ) {
$minutes1 = $dataset1[2];
}
else {
get_dataset1();
}

if ( $dataset1[3] >= 0 and $dataset1[3] <= 59 ) {
$seconds1 = $dataset1[3];
}
else {
get_dataset1();
}

if ( $i = grep { $_ eq $dataset1[4] } @zodiacname ) {
$zodiacname1 = $dataset1[4];
}
else {
get_dataset1();
}
}
# sub get_dataset1 ends

sub get_dataset2 {
print "Enter 2nd Objectname,$dgs,\',\",Zodiacname : ";
$input = ;
chomp $input;

@dataset2 = split(',',$input);

# foreach $i (0 .. $#dataset2) {
# print "$i - $dataset2[$i]\n";
# }

if ( $i = grep { $_ eq $dataset2[0] } @objectnames ) {
$objectname2 = $dataset2[0];
}
else {
get_dataset2();
}

if ( $dataset2[1] >= 0 and $dataset2[1] <= 29 ) {
$degrees2 = $dataset2[1];
}
else {
get_dataset2();
}

if ( $dataset2[2] >= 0 and $dataset2[2] <= 59 ) {
$minutes2 = $dataset2[2];
}
else {
get_dataset2();
}

if ( $dataset2[3] >= 0 and $dataset2[3] <= 59 ) {
$seconds2 = $dataset2[3];
}
else {
get_dataset2();
}

if ( $i = grep { $_ eq $dataset2[4] } @zodiacname ) {
$zodiacname2 = $dataset2[4];
}
else {
get_dataset2();
}
}
# sub get_dataset2 ends