#!/usr/bin/perl # popmoon.pl -- populate the mysql moon_phases table # (c) Copyright 2004-2006, Douglas W. Clifton, all rights reserved. # for more copyright information visit the following URI: # http://loadaveragezero.com/info/copyright.php use POSIX 'strftime'; use Time::Local 'timegm'; use Astro::MoonPhase; # phase 1 -- first # phase 2 -- full # phase 3 -- last # phase 4 -- new @phases = ( 'new', 'first', 'full', 'last', 'new' ); use DBI; require 'mysql.pl'; $ds = "DBI:mysql:database=$my{DB};host=$my{host}"; $db = DBI->connect($ds, $my{usr}, $my{pwd}); $in = 'insert into moon_phases values (?, ?)'; $sh = $db->prepare($in) or die $db->errstr; $dom = 15; $fmt = '%Y-%m-%d'; close STDERR; foreach $year (70..137) { foreach $month (0..11) { @phase = phasehunt(timegm(0, 0, 0, $dom, $month, $year)); $i = 0; foreach $phase (@phase) { $date = strftime($fmt, gmtime($phase)); unless ($seen{$date}) { $seen{$date}++; $n++ if $sh->execute($date, $phases[$i]); } $i++; } } } $sh->finish; $db->disconnect; print 'inserted ', $n, ' moon phase records.', "\n"; __END__ popmoons.pl