Skip to content

Instantly share code, notes, and snippets.

@lopnor
Created May 13, 2010 08:17
Show Gist options
  • Select an option

  • Save lopnor/399616 to your computer and use it in GitHub Desktop.

Select an option

Save lopnor/399616 to your computer and use it in GitHub Desktop.
#!perl
use strict;
use warnings;
use utf8;
use Config::Pit;
use WebService::Simple;
{
package MyParser;
use base 'WebService::Simple::Parser';
use JSON::XS;
sub parse_response { decode_json($_[1]->content) }
}
# my $config = { key => 'your recruit webservice api key' };
my $config = pit_get('webservice.recruit.co.jp');
binmode(STDOUT, ':utf8');
my $hp = WebService::Simple->new(
base_url => 'http://webservice.recruit.co.jp/hotpepper/',
param => {%$config, format => 'json'},
response_parser => MyParser->new,
);
my $area = $hp->get('small_area/v1/')->parse_response->{results}{small_area};
for (@$area) {
my $start = 1;
while (1) {
my $res = $hp->get('gourmet/v1/',
{
small_area => $_->{code},
start => $start,
count => 100,
}
)->parse_response;
scalar @{$res->{results}{shop} || []} or last;
for my $shop (@{$res->{results}{shop}}) {
print join("\t",
$shop->{id},
$shop->{small_area}{code},
$shop->{small_area}{name},
$shop->{name},
$shop->{address},
$shop->{lat},
$shop->{lng},
$shop->{urls}{pc},
), "\n";
}
$start += 100;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment