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 = '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 = ('smdesc', 'updatetime', 'map');
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->{url}::$result->{description}\n";
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::AddURLSearch($loc);
00055 my $results = MapSearch::doSearch();
00056 my $url = $results->[0]->{url};
00057 my $desc = $results->[0]->{description};
00058 my $size = $results->[0]->{imgsize};
00059 chomp $url;
00060 chomp $desc;
00061 my $file = $desc;
00062 $file =~ s/[^a-zA-Z0-9]
00063 my $path = "$dir/$file";
00064 getstore($url, $path) or $path = 'unknown.png';
00065 if (!$size) {
00066 use Image::Size;
00067 my ($x, $y) = imgsize($path);
00068 $size = "${x}x$y" if ($x && $y);
00069 }
00070 print "smdesc::$desc\n";
00071 printf "map::$path%s\n", ($size && "-$size" || '');
00072 print "updatetime::Last Updated on " . UnixDate("now", "%b %d, %I:%M %p %Z") . "\n";