Created
July 9, 2012 19:47
-
-
Save soh-i/3078484 to your computer and use it in GitHub Desktop.
Twitter検索した結果(json)を渡して、instagramのリンクから画像を落とすやつ
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 JSON::XS; | |
| use LWP::Simple; | |
| if ( scalar @ARGV != 1 ) { | |
| die"Usage: perl $0 <twitter_search_result.json>"; | |
| } | |
| my $json_in = `cat $ARGV[0]`; | |
| my $json = JSON::XS->new->utf8->decode($json_in); | |
| unless ( !$json ) { | |
| my $count = 0; | |
| foreach my $data ( @{ $json->{results} } ) { | |
| my ( $user, $text ); | |
| $user = $data->{from_user}; | |
| push my @text, $data->{text}; | |
| for my $text ( @text ) { | |
| $text =~ m/(http.+)/; | |
| my $url = $1; | |
| if ( defined $url ) { | |
| my $html = get($url); | |
| $html =~ m/\<img\sclass\=\"photo\"\ssrc\=\"(http.+)\"\s\/\>/; | |
| my $img = $1 if defined $1; | |
| my $instagram = get($img); | |
| open OUT, ">", "$count.jpg" if defined $instagram; | |
| binmode OUT; | |
| print OUT "$instagram"; | |
| close OUT; | |
| print "Done...$count"; | |
| } | |
| else { | |
| print STDERR "Error: Can not parse img $url"; | |
| } | |
| sleep (1); | |
| } | |
| $count++; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment