Skip to content

Instantly share code, notes, and snippets.

@matoken
Last active August 29, 2015 14:02
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save matoken/1e9a5455bf8ab6511c7d to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
my $WATCHDIR = '/var/www/owncloud/data/mk/files/InstantUpload/';
my $FLICKR_TOKEN = 'xxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxx';
my $jpg;
open CMD, "/usr/bin/inotifywait -m -e moved_to --format %f $WATCHDIR |";
while($jpg=<CMD>){
chomp $jpg;
my $small = $jpg;
#-- resize(Google+用)
$small =~s/\.jpg$/-2048\.jpg/i;
system("convert -resize 2048x -quality 100 $WATCHDIR/$jpg /tmp/$small");
#-- Google+ post
system("google picasa post '自動バックアップ' /tmp/$small");
system("rm /tmp/$small");
#-- Flickr post
system("/usr/bin/flickr_upload --auth_token $FLICKR_TOKEN --public 0 --friend 0 --family 0 --tag='\"InstantUpload\"' $WATCHDIR/$jpg");
}
__END__
"inotyfy-post.pl" https://gist.github.com/matoken/1e9a5455bf8ab6511c7d
@matoken
Copy link
Author

matoken commented Jun 14, 2014

これは何?

OwnCloud で自動Upload されるディレクトリをinotify で監視してPicasa の自動Upload 領域と,Flickr
にUpload するScript

Android の Ownclowd アプリで自動アップロードされた写真を監視してpost するのに使っています.

pkg install

$ sudo apt-get install libflickr-upload-perl inotify-tools googlecl

UploadDIR

Ownclowd のアップロードされるディレクトリを確認して Script の $WATCHDIR に書いておく.

get token

このScript 実行前に利用するサービスのトークンを入手しておく

Flickr

% flickr_upload --auth
1. Enter the following URL into your browser

http://api.flickr.com/services/auth/?api_key=8dcf37880da64acfe8e30bb1091376b7&perms=write&frob=72157644983537186-197058a4fdf82491-183451&api_sig=8e06c3da0b66cc512a3ec74131b3309b

2. Follow the instructions on the web page
3. Hit <Enter> when finished.
.

Your authentication token for this application is
                XXXXXXXXXXXXXXXXX-XXXXXXXXXXXXXXXX

このtoken をscript の $FLICKR_TOKEN に書いておく

google

% google --force-auth picasa list-albums
Please log in and/or grant access via your browser at:
https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=4%2F19Y3OMnTQtuJWWi31IR0sH8JgDKO&hd=default

既存のブラウザ セッションに新しいウィンドウが作成されました。

※w3m でも行けるかと思ったが,2段階認証後JavaScriptが必要と言われて失敗した.リモートサーバ環境 ではssh のX 転送で凌いた

$ ssh -XC user@host

実行

$ wget https://gist.github.com/matoken/85fb80fc5af982ca40e4/raw/65ccfc65a7c14d8e44d6965e14f76e79290a637a/inotyfy-post.pl
$ chmod +x inotyfy-post.pl
$ ./inotyfy-post.pl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment