Skip to content

Instantly share code, notes, and snippets.

@niratama
Last active August 29, 2015 14:24
Show Gist options
  • Save niratama/a4ae50b227b69bfa5322 to your computer and use it in GitHub Desktop.
Save niratama/a4ae50b227b69bfa5322 to your computer and use it in GitHub Desktop.
LAWSON×INGRESS MACHI café DRINK CARD 販売店一覧CSV作成ツール
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use Encode qw(encode_utf8 decode_utf8);
use JSON;
use File::Slurp;
use LWP::Simple;
use Geo::Coordinates::Converter;
my $store_code = {
'1' => 'ローソン',
'2' => 'ナチュラルローソン',
'4' => 'ローソンストア100'
};
my $area_code = {
'1' => ['北海道', 'hokkaido'],
'2' => ['東北', 'tohoku'],
'3' => ['関東', 'kanto'],
'4' => ['北陸', 'hokuriku'],
'5' => ['近畿', 'kinki'],
'6' => ['中国', 'chugoku'],
'7' => ['四国', 'shikoku'],
'8' => ['九州', 'kyushu'],
'9' => ['沖縄', 'okinawa']
};
my $pref_code = {
# [prefName, lat, lon]
'01' => ['北海道', '43.0646147', '141.3468074'],
'02' => ['青森', '40.8243077', '140.7399984'],
'03' => ['岩手', '39.7036194', '141.1526839'],
'04' => ['宮城', '38.2688373', '140.8721'],
'05' => ['秋田', '39.7186135', '140.1023643'],
'06' => ['山形', '38.2404355', '140.3636333'],
'07' => ['福島', '37.7502986', '140.4675514'],
'08' => ['茨城', '36.3418112', '140.4467935'],
'09' => ['栃木', '36.565725', '139.8835651'],
'10' => ['群馬', '36.3906675', '139.0604061'],
'11' => ['埼玉', '35.8569991', '139.6488487'],
'12' => ['千葉', '35.6050574', '140.1233063'],
'13' => ['東京', '35.6894875', '139.6917064'],
'14' => ['神奈川', '35.4475073', '139.6423446'],
'15' => ['新潟', '37.9025518', '139.0230946'],
'16' => ['富山', '36.6952907', '137.2113383'],
'17' => ['石川', '36.5946816', '136.6255726'],
'18' => ['福井', '36.0651779', '136.2215269'],
'19' => ['山梨', '35.6641575', '138.5684486'],
'20' => ['長野', '36.6512986', '138.1809557'],
'21' => ['岐阜', '35.3912272', '136.7222906'],
'22' => ['静岡', '34.9771201', '138.3830845'],
'23' => ['愛知', '35.1801883', '136.9065647'],
'24' => ['三重', '34.7302829', '136.5085883'],
'25' => ['滋賀', '35.0045306', '135.8685899'],
'26' => ['京都', '35.0212466', '135.7555968'],
'27' => ['大阪', '34.6862971', '135.5196609'],
'28' => ['兵庫', '34.6912688', '135.1830706'],
'29' => ['奈良', '34.6853345', '135.8327421'],
'30' => ['和歌山', '34.2259867', '135.1675086'],
'31' => ['鳥取', '35.5038906', '134.2377356'],
'32' => ['島根', '35.4722952', '133.0504997'],
'33' => ['岡山', '34.6617511', '133.9344057'],
'34' => ['広島', '34.3965603', '132.4596225'],
'35' => ['山口', '34.1859563', '131.4706493'],
'36' => ['徳島', '34.0657179', '134.5593601'],
'37' => ['香川', '34.3401491', '134.0434436'],
'38' => ['愛媛', '33.8416238', '132.7656808'],
'39' => ['高知', '33.5597062', '133.5310786'],
'40' => ['福岡', '33.6065756', '130.418297'],
'41' => ['佐賀', '33.2494416', '130.2997942'],
'42' => ['長崎', '32.7448388', '129.8737562'],
'43' => ['熊本', '32.789827', '130.7416672'],
'44' => ['大分', '33.2381718', '131.6126189'],
'45' => ['宮崎', '31.9110956', '131.4238934'],
'46' => ['鹿児島', '31.5610825', '130.5577279'],
'47' => ['沖縄', '26.2124013', '127.6809317']
};
my $json = get('http://store.lawson.co.jp/json/new_json/ingress1.json');
my $data = JSON->new->utf8->decode($json);
my $city_code = $data->{cities};
foreach my $area_id (keys %{$data->{stores}}) {
my @list;
push @list, '店舗名,住所,緯度,経度';
my $area = $area_code->{$area_id}->[0];
my $prefs = $data->{stores}->{$area_id};
foreach my $pref_id (keys %$prefs) {
my $pref = $pref_code->{$pref_id}->[0];
my $cities = $prefs->{$pref_id};
foreach my $city_id (keys %$cities) {
my $city = $city_code->{$pref_id}->{$city_id};
my $stores = $cities->{$city_id};
foreach my $store (@$stores) {
my $kyoten_id = $store->{kyotenId};
my $store_id = $store->{store};
my $storename = $store->{storename};
my $address = $store->{address};
my $geo = Geo::Coordinates::Converter->new(lat => $store->{lat}, lng => $store->{lon}, datum => 'tokyo');
$geo->convert('wgs84');
my $lat = $geo->lat;
my $lon = $geo->lng;
push @list, "${storename}店,${address},${lat},${lon}";
}
}
}
write_file("${area}.csv", encode_utf8(join("\n", @list)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment