Created
May 31, 2013 15:30
-
-
Save oogali/5685780 to your computer and use it in GitHub Desktop.
Get sunrise times?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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).