Skip to content

Instantly share code, notes, and snippets.

@ynkdir
Last active May 4, 2019 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ynkdir/c84eb0263db7e9f784f708a1ec1c5d9d to your computer and use it in GitHub Desktop.
Save ynkdir/c84eb0263db7e9f784f708a1ec1c5d9d to your computer and use it in GitHub Desktop.
国立国会図書館サーチを使って新刊コミック(に限らず)を検索する
# 国立国会図書館サーチを使って新刊コミック(に限らず)を検索する
#
# 国立国会図書館サーチ API仕様の概要
# https://iss.ndl.go.jp/information/api/riyou/
#
# 2019年4月1日 国立国会図書館の書誌データは、様々な用途で自由にご利用いただけます
# https://www.ndl.go.jp/jp/news/fy2019/190401_02.html
#
# 出版情報登録センターとの連携強化による機能改善のお知らせ
# https://iss.ndl.go.jp/information/2018/06/28_announce_jpro/
#
# 例: ndlsearch.py "creator any \"緑川ゆき 九井諒子\" and from=2019-04"
import sys
import urllib.parse
import urllib.request
import xml.etree.ElementTree as ET
url = "http://iss.ndl.go.jp/api/sru?" + urllib.parse.urlencode({
"operation": "searchRetrieve",
"recordPacking": "xml",
"recordSchema": "dcndl",
"onlyBib": "true",
"query": sys.argv[1],
})
ns = {
"srw": "http://www.loc.gov/zing/srw/",
"foaf": "http://xmlns.com/foaf/0.1/",
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"dc": "http://purl.org/dc/elements/1.1/",
"owl": "http://www.w3.org/2002/07/owl#",
"dcterms": "http://purl.org/dc/terms/",
"dcndl": "http://ndl.go.jp/dcndl/terms/",
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
}
res = urllib.request.urlopen(url).read().decode("utf-8")
root = ET.fromstring(res)
lines = []
for b in root.findall(".//dcndl:BibResource", ns):
title = b.find("dcterms:title", ns).text
creator = "・".join([e.text for e in b.findall("dcterms:creator/foaf:Agent/foaf:name", ns)])
issued = b.find("dcterms:issued", ns).text
# 他おもしろそうな属性
# dcterms:abstract
# dcterms:tableOfContents
# foaf:thumbnail
lines.append(f"{issued} {title} {creator}")
for line in sorted(lines):
print(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment