Japan Search Gallery Tools

Tools for working with Japan Search Gallery

Install

pip install jps_gallery_tools

実行例

GoogleColabのノートブック

How to use

See the documentation for full details of the Japan Search Gallery API Client.

ギャラリーの作成

from jps_gallery_tools.api import *
gallery = JpsCuration()
gallery.setLangMetadata('title', 'ja', 'はじめてのギャラリー')
gallery.setLangMetadata('summary', 'ja', 'はじめてのギャラリーを作成します。')
gallery.setLangMetadata("responsibility", "ja", "中村覚")
gallery.addTag("はじめて")
gallery.addTag("テスト")

トップ画像

original_url = "https://blogger.googleusercontent.com/img/a/AVvXsEiTjjaWkCHeCslxeKujaQotjuR_HvhOHen7Ql7rQV8nmQl4ivLRF_CSabMY-JLJHNL-xHMe3VDyA9F-iv1RtQ2jFTk1Vnjck-veKLUZPdYqCcjzHkc8SGKb1fyZ_x8W66aTrSXQ78UN3CnyBakwwmmH_hmPKeEsTzq8J3e2zzUMylmDjCZ0LClPByBRRw=s400"
thumbnail_url = "https://blogger.googleusercontent.com/img/a/AVvXsEiTjjaWkCHeCslxeKujaQotjuR_HvhOHen7Ql7rQV8nmQl4ivLRF_CSabMY-JLJHNL-xHMe3VDyA9F-iv1RtQ2jFTk1Vnjck-veKLUZPdYqCcjzHkc8SGKb1fyZ_x8W66aTrSXQ78UN3CnyBakwwmmH_hmPKeEsTzq8J3e2zzUMylmDjCZ0LClPByBRRw=s180-c"
title = "初日の出のキャラクター"
source = "いらすとや"
top_image = JpsCurationUrlImage(original_url, title, source, thumbnail_url)
gallery.setImage(top_image)

テキスト

part_01= JpsCurationText()
gallery.addPart(part_01)
part_01.addText("ja", "テキスト。テキスト。テキスト。テキスト。")

リスト

part_02 = JpsCurationList("tile")
part_02.setLangMetadata("title", "ja", "リストのタイトル")
part_02.setLangMetadata("title", "en", "List Title")
gallery.addPart(part_02)

4件の画像を追加

for i in range(4):
    item = JpsCurationListExternalLink()
    part_02.addPart(item)
    item.setLangMetadata("title", "ja", "外部リンクのタイトル")
    item.setImage(top_image)

年表

part_03 = JpsCurationTimeline(1800, 2050)
gallery.addPart(part_03)
part_03.setLangMetadata("title", "ja", "年表のタイトル")
part_03.setLangMetadata("title", "en", "Timeline Title")
part_03_01 = JpsCurationTimepoint("時点のタイトル", "Timepoint Title", 1877, 1877)
part_03.addPart(part_03_01)
part_03_01_01 = JpsCurationText()
part_03_01.addPart(part_03_01_01)
part_03_01_01.addText("ja", "時点のテキスト。時点のテキスト。時点のテキスト。時点のテキスト。")

地図

part_04 = JpsCurationList("map")
gallery.addPart(part_04)
part_04.setLangMetadata("title", "ja", "地図のタイトル")
part_04.setLangMetadata("title", "en", "Map Title")

part_04.setMetadata("openActionType", "link")
part_04.setMetadata("mapParam", {
    "center": {
        "lat": 35.713736762125464,
        "lon": 139.76272050237696
    },
    "zoom": 15,
    "mode": "NORMAL"
})
import copy
from pprint import pprint

item_04_01 = copy.copy(item)

item_04_01.setMetadata("latlon", {
    "lat": 35.713333,
    "lon": 139.762222
})
part_04.addPart(item_04_01)

出力

gallery.save("tmp/gallery.json")
b = gallery.encode(curationType="GALLERY")
import IPython
from IPython.display import display, HTML

lang = "ja"
 
htm = HTML(f'''\
<div
        class="jps"
        data-lang="{lang}"
        data-cur="{b}">
</div>
<script src="https://jpsearch.go.jp/assets/js/wp.bundle.js"></script>
''')
 
display(htm)