Created
July 16, 2012 07:25
-
-
Save soh-i/3121343 to your computer and use it in GitHub Desktop.
get_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/evn perl | |
| use strict; | |
| use warnings; | |
| use 5.17.0; | |
| use LWP::UserAgent; | |
| use LWP::Simple; | |
| use JSON qw/decode_json/; | |
| my $uri = URI->new('http://search.twitter.com/search.json'); | |
| my $search_query = 'らーめん+OR+ラーメン+instagr.am'; | |
| $uri->query_form( | |
| lang => 'ja', | |
| q => "$search_query", | |
| rpp => "1500", | |
| page => "1" | |
| ); | |
| my $ua = LWP::UserAgent->new; | |
| my $res = $ua->get($uri); | |
| my $json = decode_json ( $res->content ); | |
| if ( defined $json ) { | |
| foreach my $tw ( @{ $json->{results} } ) { | |
| my $text = $tw->{text}; | |
| my $date = $tw->{created_at}; | |
| $date =~ s/\s+|\s//g; | |
| if ( defined $text ) { | |
| $text =~ m/(http\:.+)/; | |
| my $url = $1 if defined $1; | |
| my $html = get($url); | |
| if ( $html ) { | |
| $html =~ m/\<img\sclass\=\"photo\"\ssrc\=\"(http.+)\"\s\/\>/; | |
| my $instagram = $1 if defined $1; | |
| my $img = get($instagram); | |
| open OUT, '>', "$date.jpg"; | |
| binmode OUT; | |
| print OUT $img; | |
| say "Done...$date\n"; | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment