GitBucket
4.21.2
Toggle navigation
Snippets
Sign in
Files
Branches
1
Releases
Issues
Pull requests
Labels
Priorities
Milestones
Wiki
Forks
nigel.stanger
/
Digital_Repository
Browse code
- Changed to use 'which' instead of the value of $? to detect whether
download executable (curl, wget, ...) exists.
master
1 parent
024dea4
commit
59696d6eb8a85d2482b78bb20c11c4f6135dad0a
nstanger
authored
on 12 Jan 2010
Patch
Showing
1 changed file
Repositories/otago_eprints3/otago_eprints/cfg/cfg.d/twitter.pl
Ignore Space
Show notes
View
Repositories/otago_eprints3/otago_eprints/cfg/cfg.d/twitter.pl
$c->{eprint_status_change} = sub { my( $eprint, $old_status, $new_status ) = @_; if( $new_status eq "archive" ) { my $twitter_username="OtagoSoBEprints"; my $twitter_password="mmpcfjXIm1jY0cU"; # NJS 2009-12-07: Rewrote completely to check for existence # of curl, wget, etc. Also now truncates the title if the # tweet would otherwise be longer than 140 characters. my $isgdCmd = ''; my $twitterCmd = ''; my $urlCmd = ''; my $shorturl = ''; my $title = $eprint->get_value( "title" ); $title =~ s/'/\\'/g; if ( length( $title ) > 118 ) { $title = substr( $title, 0, 118 ) . 'É'; } SWITCH: foreach ( 'curl', 'wget' ) # add others here and below { # NJS 2010-01-12: Changed to use which instead of $? value. # Check that the command exists using which. If it exists # then the output of which will start with '/', otherwise # it won't (it will usually be empty or something like # "no such ..." or "foo: not found") $urlCmd = `which $_`; chomp $urlCmd; if ( $urlCmd =~ m|^/| ) { if ( /curl/ ) { $isgdCmd = "$urlCmd --silent 'http://is.gd/api.php?longurl=" . $eprint->get_url . "'"; $shorturl = `$isgdCmd`; $twitterCmd = "$urlCmd --silent --basic --user $twitter_username:$twitter_password --data status='$title - $shorturl' http://twitter.com/statuses/update.xml"; `$twitterCmd &`; last SWITCH; } if ( /wget/ ) { $isgdCmd = "$urlCmd --quiet --output-document=- 'http://is.gd/api.php?longurl=" . $eprint->get_url . "'"; $shorturl = `$isgdCmd`; $twitterCmd = "$urlCmd --quiet --http-user=$twitter_username --http-password=$twitter_password --post-data='status=$title - $shorturl' http://twitter.com/statuses/update.xml"; `$twitterCmd &`; last SWITCH; } } } } };
$c->{eprint_status_change} = sub { my( $eprint, $old_status, $new_status ) = @_; if( $new_status eq "archive" ) { my $twitter_username="OtagoSoBEprints"; my $twitter_password="mmpcfjXIm1jY0cU"; # NJS 2009-12-07: Rewrote completely to check for existence # of curl, wget, etc. Also now truncates the title if the # tweet would otherwise be longer than 140 characters. my $isgdCmd = ''; my $twitterCmd = ''; my $shorturl = ''; my $title = $eprint->get_value( "title" ); $title =~ s/'/\\'/g; if ( length( $title ) > 118 ) { $title = substr( $title, 0, 118 ) . 'É'; } SWITCH: foreach ( 'curl', 'wget' ) # add others here and below { # Try to call the command, if it's not in the path then $? # will be -1 and $! will be 'No such file or directory'. # If nothing works, just fail silently. system( $_ ); if ( $? != -1 ) { if ( /curl/ ) { $isgdCmd = "curl --silent 'http://is.gd/api.php?longurl=" . $eprint->get_url . "'"; $shorturl = `$isgdCmd`; $twitterCmd = "curl --silent --basic --user $twitter_username:$twitter_password --data status='$title - $shorturl' http://twitter.com/statuses/update.xml"; `$twitterCmd &`; last SWITCH; } if ( /wget/ ) { $isgdCmd = "wget --quiet --output-document=- 'http://is.gd/api.php?longurl=" . $eprint->get_url . "'"; $shorturl = `$isgdCmd`; $twitterCmd = "wget --quiet --http-user=$twitter_username --http-password=$twitter_password --post-data='status=$title - $shorturl' http://twitter.com/statuses/update.xml"; `$twitterCmd &`; last SWITCH; } } } } };
Show line notes below