Skip to content

Instantly share code, notes, and snippets.

@nekoruri
Created November 11, 2011 20:13
Show Gist options
  • Save nekoruri/1359092 to your computer and use it in GitHub Desktop.
Save nekoruri/1359092 to your computer and use it in GitHub Desktop.
ssb2bklg Stack Stock Books APIのJSONからブクログインポート用CSVへのコンバータ
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use JSON;
use Data::Dumper;
my @stocks;
# ssb1.json - ssb12.json のような形で用意する。
# % for i in `seq 1 13`; do
# curl http://stack.nayutaya.jp/api/user/name/USERNAME/stocks/read.json\?include_books=true\&include_histories=true\&page=$i > ssb$i.json
# done
foreach my $i ( 1 .. 11 ) {
local $/;
open( my $fh, '<', "ssb$i.json" );
my $json_text = <$fh>;
close $fh;
my $ssb = decode_json( $json_text );
push @stocks, @{$ssb->{response}{stocks}};
}
# 件数表示
warn scalar @stocks;
open( my $csv, '>:encoding(cp932)', 'bklg.csv');
foreach my $stock (@stocks) {
my $add = $stock->{histories}[0]{date};
my $read = $stock->{histories}[-1]{date};
print $csv qq|"未設定","$stock->{book}{isbn13}","$add","","","3","読了","$read"\n|;
}
close $csv;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment