Skip to content

Instantly share code, notes, and snippets.

@soh-i
Created July 16, 2012 10:42
Show Gist options
  • Select an option

  • Save soh-i/3122082 to your computer and use it in GitHub Desktop.

Select an option

Save soh-i/3122082 to your computer and use it in GitHub Desktop.
ラーメン二郎の画像をinstagramから700枚くらい集めた
#!/usr/bin/env 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 = 'ラーメン二郎+instagr.am';
for my $date ( qw/8 9 10 11 12 13 14 15 16/ ) {
$uri->query_form(
lang => 'ja',
q => "$search_query",
rpp => "1500",
page => "1",
until => "2012-07-$date",
);
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, '>', "./img/$date.jpg";
binmode OUT;
print OUT $img;
say "Done...$date";
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment