Created
September 7, 2012 07:56
-
-
Save equinox79/3664210 to your computer and use it in GitHub Desktop.
指定されたディレクトリを監視して画像ファイルがうpされるとpyazoに投稿
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/env perl | |
use strict; | |
use warnings; | |
use File::Monitor::Lite; | |
use HTTP::Request::Common; | |
use IO::File; | |
use LWP::UserAgent; | |
my $upload_path = '/foo/bar'; # ここを直す | |
my $pyazo_url = 'http://yairc.cfe.jp:5000/'; | |
my $fh = IO::File->new(); | |
my $ua = LWP::UserAgent->new(); | |
my $dmon = File::Monitor::Lite->new( | |
in => $upload_path, | |
name => qr/.+\.\U(png|jpg|jpeg)/, | |
); | |
$ua->agent('Gyazo/1.0'); | |
while ( $dmon->check() and sleep 1 ) { | |
next unless ( $dmon->anychange ); | |
my @created_files = $dmon->created; | |
for my $filename (@created_files) { | |
next unless ( $fh->open($filename) ); | |
my $res = $ua->request( | |
POST( | |
$pyazo_url, | |
Content_Type => 'form-data', | |
Content => { imagedata => [$filename] }, | |
) | |
); | |
print sprintf( "%s ... %s\n", $filename, $res->code ); | |
print $res->decoded_content . "\n" if ( $res->is_success ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment