Created
May 13, 2010 08:17
-
-
Save lopnor/399616 to your computer and use it in GitHub Desktop.
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
| #!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