Created
August 4, 2010 07:02
-
-
Save miyamuko/507771 to your computer and use it in GitHub Desktop.
StackStockBooks のもう読み終えた本のリストを取得して ChangeLog 形式で生成する
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
| ;; StackStockBooks のもう読み終えた本のリストを取得して ChangeLog 形式で生成する | |
| ;; http://stack.nayutaya.jp/ | |
| (defpackage :stack-stock-books | |
| (:nicknames :ssb) | |
| (:use :lisp :editor)) | |
| (in-package :stack-stock-books) | |
| (export '(StackStockBooksの読み終えたリストをChangeLog形式で生成 | |
| )) | |
| (require "cmu_loop") | |
| (require "json") | |
| (defun StackStockBooksの読み終えたリストをChangeLog形式で生成 (user fullname &key max-page) | |
| (let ((current-date nil) | |
| ;; τなどのギリシャ文字が化けないようにする | |
| ;; (let ((*unicode-to-half-width* nil)) | |
| ;; (unicode-char (char-unicode #\τ))) => #\τ | |
| ;; | |
| ;; (let ((*unicode-to-half-width* t)) | |
| ;; (unicode-char (char-unicode #\τ))) => #\x03f4 | |
| (*unicode-to-half-width* nil)) | |
| (dolist (read-list (sort (get-user-stocks-by-state user "read" :include-books t :max-page max-page) | |
| #'string> | |
| :key #'(lambda (stock) (json:json-values stock "date")))) | |
| (multiple-value-bind (date title isbn10) | |
| (json:json-values read-list '("date" ("book" "title") ("book" "isbn10"))) | |
| (when (or (not current-date) | |
| (not (equal current-date date))) | |
| (setf current-date date) | |
| (insert (format nil "~A ~A~%" date fullname)) | |
| (insert #\LFD)) | |
| (insert #\TAB (format nil "* 読了: ~A~%" title)) | |
| (insert #\TAB (format nil "http://www.amazon.co.jp/dp/~A~%" isbn10)) | |
| (insert #\LFD) | |
| )))) | |
| (defun get-user-stocks-by-state (name state &key | |
| max-page | |
| include-books include-authors include-histories) | |
| (loop | |
| for page from 1 to (or max-page most-positive-fixnum) | |
| with stocks and pagination | |
| do (multiple-value-setq (stocks pagination) | |
| (get-user-stocks-by-state1 name state | |
| :include-books include-books | |
| :include-authors include-authors | |
| :include-histories include-histories | |
| :page page)) | |
| nconc stocks | |
| while (json:json-values pagination "has_next_page") | |
| do (sit-for 1) | |
| )) | |
| (defun get-user-stocks-by-state1 (name state &key include-books include-authors include-histories page) | |
| (let ((json (json:json-decode | |
| (xhr:xhr-get (format nil "http://stack.nayutaya.jp/api/user/name/~A/stocks/~A.json" name state) | |
| :query `(:include_books ,(format nil "~:[false~;true~]" include-books) | |
| :include_authors ,(format nil "~:[false~;true~]" include-authors) | |
| :include_histories ,(format nil "~:[false~;true~]" include-histories) | |
| :page ,page | |
| ) | |
| :key 'xhr:xhr-response-text)))) | |
| (json:json-values json '(("response" "stocks") | |
| "pagination")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment