#!/usr/bin/env perl use strict; use warnings; use Getopt::Std; use File::Find; # 2005 Alf Eaton alf@hubmed.org http://hublog.hubmed.org # Written for Mac OS X, should be quite easily modifiable to run elsewhere # Modified for WinXP/Cygwin 2005 Peter Li # Downloads photos from flickr's 'interesting' listing. Nice for changing # screensaver or desktop wallpaper images. By default, uses the cygwin utility # djpeg to scale down images that are much larger than necessary for most # desktops (i.e. images greater than 1MB by default). To disable this scaling, # run with option -m 0. # # Run 'ntrstng-cyg -h' for help with command line arguments. # # To run cron from cygwin: # Setup cron: 'cygrunsrv -I cron -p /usr/sbin/cron -a -D' # Make sure '/var/run/cron.pid' is owned by SYSTEM # Start cron: 'cygrunsrv -S cron' # Verify cron is running: 'ps -a' # Enter crontab 'crontab -e' # E.g.: '0 0 * * * ntrstng-cyg -sp3' # Crontab format guide: 'man 5 crontab' # # Google 'wallpaper changer powertoy' for desktop wallpaper rotation my $days = 2; my $max_file = 1000000; my $pages = 1; my $curl_args = '--insecure --progress-bar'; my $base_dir; ###################################### # Parse command line options, initialize parameters my %options = (); getopts('d:him:o:p:qsz', \%options); print_help() if $options{h}; $days = $options{d} if defined($options{d}); $max_file = $options{m} if defined($options{m}); $pages = $options{p} if defined($options{p}); $options{q} = 1 if $options{s}; # Run quiet if --silent $curl_args .= ' --silent' if $options{q}; $curl_args .= ' --compressed' if $options{z}; if (defined($options{o})) { $base_dir = $options{o}; } else { # Hopefully get the WinXP user home directory from environment vars... my $homedrive = $ENV{HOMEDRIVE}; my $homepath = $ENV{HOMEPATH}; unless ($homepath and $homedrive) { throw_homeerr(\%options); } { local $/ = ':'; chomp($homedrive); } my $homedir = "/cygdrive/$homedrive" . join('/', split(/\\/, $homepath)); $base_dir = "$homedir/My Documents/My Pictures/flickr/"; } my $img_dir = "$base_dir/interesting"; my $arch_dir = "$base_dir/archive"; # Perhaps create directories, but can't do anything if file already exists by # same name if ($options{i}) { unless (-e "$img_dir") { system("mkdir -p '$img_dir' 2>/dev/null"); } unless (-e "$arch_dir") { system("mkdir -p '$arch_dir' 2>/dev/null"); } } # If directories still don't exist, hang unless (-d "$img_dir") { throw_direrr($img_dir, \%options); } unless (-d "$arch_dir") { throw_direrr($arch_dir, \%options); } # Move old images to archive dir system("mv '$img_dir/'*.jpg '$arch_dir' 2>/dev/null"); # Build URLs for interesting photos, retrieve user-specified number of pages my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = gmtime(time-(60*60*24*$days)); # Current time, minus the specified number of days ago my $baseurl = sprintf "http://flickr.com/explore/interesting/%4d/%02d/%02d", 1900+$year, $mon+1, $mday; for (my $i = 1; $i <= $pages; $i++) { # Retrieve page of interesting photo links my $url = "$baseurl/page$i/"; print "$url\n" unless $options{q}; my $page = `curl --silent '$url'` or last; # Parse photo URLs from page, retrieve photos while ($page =~ m|
\s*