Created
July 11, 2020 07:43
-
-
Save osamu2001/2f4613c9473f427f2c1536f47599ab81 to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
function rowToString(array $row) | |
{ | |
$amzn = '[link http://amazon.jp/dp/' . $row[0] . ']'; | |
$title = str_replace('[',' ',str_replace(']',' ',$row[1])); | |
$author = $row[2]; | |
$d = strtotime($row[3]); | |
$ym = date('Y-m',$d); | |
$ymd = date('Y-m-d',$d); | |
$v = " [" . $title . "] $amzn [" . $author . "]"; | |
return [$ym,$ymd,$v]; | |
} | |
$handle = fopen("Kindle.csv", "r"); | |
$books = []; | |
while (($data = fgetcsv($handle))) { | |
[$ym,$ymd,$v] = rowToString($data); | |
if ($ym !== '1970-01') | |
$books[$ym][$ymd][] = $v; | |
} | |
ksort($books); | |
$pages = []; | |
foreach ($books as $ym => $ymbooks) { | |
$title = 'Kindle::' . $ym; | |
$lines = [$title]; | |
ksort($ymbooks); | |
foreach ($ymbooks as $ymd => $ymdbooks) { | |
$lines[] = '[' . $ymd . ']'; | |
foreach ($ymdbooks as $b) { | |
$lines[] = $b; | |
} | |
$lines[] = ""; | |
} | |
$lines[] = '[Kindle]'; | |
$lines[] = '[Kindle::' . substr($ym,0,4) . ']'; | |
$page['title'] = $title; | |
$page['lines'] = $lines; | |
$pages[] = $page; | |
} | |
echo json_encode(['pages' => $pages]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment