00001 #!/usr/bin/perl -w
00002 use strict;
00003 use Getopt::Std;
00004 use LWP::Simple;
00005 use Date::Manip;
00006 use MapSearch;
00007 use Data::Dumper;
00008 our ($opt_v, $opt_t, $opt_T, $opt_l, $opt_u, $opt_d);
00009
00010 my $name = 'Animated-Map-Download';
00011 my $version = 0.1;
00012 my $author = 'Lucien Dunning';
00013 my $email = 'ldunning@gmail.com';
00014 my $updateTimeout = 10*60;
00015 my $retrieveTimeout = 30;
00016 my @types = ('amdesc', 'updatetime', 'animatedimage');
00017 my $dir = "./";
00018
00019 getopts('Tvtlu:d:');
00020
00021 if (defined $opt_v) {
00022 print "$name,$version,$author,$email\n";
00023 exit 0;
00024 }
00025
00026 if (defined $opt_T) {
00027 print "$updateTimeout,$retrieveTimeout\n";
00028 exit 0;
00029 }
00030 if (defined $opt_l) {
00031 MapSearch::AddDescSearch(shift);
00032 foreach my $result (@{MapSearch::doSearch()}) {
00033 print "$result->{animation}::$result->{description}\n" if ($result->{animation});
00034 }
00035 exit 0;
00036 }
00037
00038 if (defined $opt_t) {
00039 foreach (@types) {print; print "\n";}
00040 exit 0;
00041 }
00042
00043 if (defined $opt_d) {
00044 $dir = $opt_d;
00045 }
00046
00047 my $loc = shift;
00048
00049 if (!defined $loc || $loc eq "") {
00050 die "Invalid usage";
00051 }
00052
00053 #should only get one location result since its by url, assuming things is fun :)
00054 MapSearch::AddAniSearch($loc);
00055 my $results = MapSearch::doSearch();
00056 my $base = $results->[0]->{animation};
00057 my $desc = $results->[0]->{description};
00058 my $size = $results->[0]->{imgsize};
00059 my $file = $desc;
00060 $file =~ s/[^a-zA-Z0-9]
00061 my $path = "$dir/$file-";
00062 my $i = 0;
00063 foreach my $image (sort @{$results->[0]->{images}}) {
00064 getstore("$base/$image", $path . "$i");
00065 ++$i;
00066 }
00067 # assume all the same size, so just check first
00068 if (!$size) {
00069 use Image::Size;
00070 my ($x, $y) = imgsize("${path}0");
00071 $size = "${x}x$y" if ($x && $y);
00072 }
00073
00074
00075 print "amdesc::$desc\n";
00076 printf "animatedimage::${path}%%1-$i%s\n", ($size && "-$size" || '');
00077 print "updatetime::Last Updated on " . UnixDate("now", "%b %d, %I:%M %p %Z") . "\n";