Created
January 26, 2010 14:50
-
-
Save kan/286890 to your computer and use it in GitHub Desktop.
This file contains 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 strict; | |
use warnings; | |
use utf8; | |
use Filesys::Notify::Simple; | |
use Flickr::Upload; | |
my $watcher = Filesys::Notify::Simple->new( [ $ARGV[0] ] ); | |
my $ua = Flickr::Upload->new( | |
{ | |
'key' => 'xxxxxxxxxx', | |
'secret' => 'xxxxxxxx', | |
} | |
); | |
my $auth_token = 'xxxxxx'; | |
while (1) { | |
$watcher->wait( | |
sub { | |
for my $event (@_) { | |
print "$event->{path} upload to flickr.\n"; | |
$ua->upload( | |
'photo' => $event->{path}, | |
'auth_token' => $auth_token, | |
'tags' => 'test', | |
'is_public' => 0, | |
'is_friend' => 0, | |
'is_family' => 0 | |
) or die "Failed to upload."; | |
print "upload complete.\n"; | |
} | |
} | |
); | |
} | |
__END__ | |
TODO | |
- daemonize | |
- config (photo param, tags, etc) | |
- auth token auto get | |
sub getFrob { | |
my $ua = shift; | |
my $res = $ua->execute_method("flickr.auth.getFrob"); | |
return undef unless defined $res and $res->{success}; | |
# FIXME: error checking, please. At least look for the node named 'frob'. | |
return $res->{tree}->{children}->[1]->{children}->[0]->{content}; | |
} | |
sub getToken { | |
my $ua = shift; | |
my $frob = shift; | |
my $res = $ua->execute_method("flickr.auth.getToken", | |
{ 'frob' => $frob } ); | |
return undef unless defined $res and $res->{success}; | |
# FIXME: error checking, please. | |
return $res->{tree}->{children}->[1]->{children}->[1]->{children}->[0]->{content}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment