Skip to content

Instantly share code, notes, and snippets.

@oogali
Created May 31, 2013 15:30
Show Gist options
  • Select an option

  • Save oogali/5685780 to your computer and use it in GitHub Desktop.

Select an option

Save oogali/5685780 to your computer and use it in GitHub Desktop.
Get sunrise times?
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request;
$city = shift || die "startoftheday <city> <state>";
$state = shift || die "startoftheday <city> <state>";
@time = localtime;
$year = $time[5] + 1900;
$month = $time[4] + 1;
$day = $time[3];
printf("Fetching sun and mooon values for %02d/%02d/%04d\n", $month, $day, $year);
$ua = LWP::UserAgent->new;
$response = $ua->post("http://aa.usno.navy.mil/cgi-bin/aa_pap.pl",
[ FFX => "1",
ID => "LNK",
xxy => $year,
xxm => $month,
xxd => $day,
st => $state,
place => $city,
ZZZ => "END",
]);
if ($response->content =~ /Begin civil twilight\s+(.+)\s+(a|p).m./) {
printf("\tTwilight: %s%sm\n", $1, $2);
}
if ($response->content =~ /Sunrise\s+(\d+):(\d+)\s+(a|p).m./) {
printf("\tSunrise: %d:%02d%sm (Golden Hour: Sunrise to %d:%02d%sm)\n", $1, $2, $3, $1 + 1, $2, $3);
}
if ($response->content =~ /Sunset\s+(\d+):(\d+)\s+(a|p).m./) {
printf("\tSunset: %d:%02d%sm (Golden Hour: %d:%02d%sm to Sunset)\n", $1, $2, $3, $1 - 1, $2, $3);
}
printf("%s\n", $response->content);
exit;
@oogali
Copy link
Author

oogali commented May 31, 2013

I think I used this in conjunction with some other script via cron to dynamically set my alarm (which was mpg123 pointed at a wakeup/ directory).

$ ls -la startoftheday
-rwxr-xr-x  1 missnglnk  staff  1057 Mar 17  2005 startoftheday

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment