Skip to content

Instantly share code, notes, and snippets.

@tamoot
Last active December 18, 2015 03:38
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 tamoot/5719135 to your computer and use it in GitHub Desktop.
Save tamoot/5719135 to your computer and use it in GitHub Desktop.
お昼休みに書いた #tDiary 用NHK番組情報埋め込みプラグイン(動作全く未検証)
# -*- coding: utf-8 -*-
#
# nhk_program_info.rb - embedded NHK program information
# refer to the URL below.
# http://www2.nhk.or.jp/api/docs/v1/
#
# Copyright (C) 2013, tamoot <tamoot+tdiary@gmail.com>
# You can redistribute it and/or modify it under GPL2.
#
require 'json'
require 'open-uri'
def nhk_program_info(id, area = @conf['nhk_api.default.area'])
nhk_endpoint = "http://api.nhk.or.jp/v1/pg/info/#{area}/#{id}.json?key=#{@conf['nhk_api.id']}"
json = JSON::parse(open(nhk_endpoint))
stime = Time::parse(json["start_time"]).strftime("%Y/%m/%d %H:%M:%S")
etime = Time::parse(json["end_time"]).strftime("%Y/%m/%d %H:%M:%S")
return <<PROGRAM_HTML
<div class="amazon-detail">
<a href="#{json["urls"]["program_url"]}">
<img src="#{json["program_logo"]}" alt="#{@conf.to_native json["title"]}" class="amazon-detail left">
<div class="amazon-detail-desc">
<span class="amazon-title">#{h json["title"]}</span><br>
<span class="amazon-title">#{h json["subtitle"]}</span><br>
<span class="amazon-title">#{h json["service_"]["service_name"]}</span><br>
<span class="amazon-price">#{h stime} - #{etime}</span><br>
</div>
<br style="clear: left">
</a>
</div>
PROGRAM_HTML
end
add_conf_proc( 'nhk', 'NHK API' ) do
if @mode == 'saveconf' then
@conf['nhk_api.id'] = @cgi.params['nhk_api.id'][0]
end
<<-HTML
<h3 class="subtitle">API key</h3>
<p><input name="nhk_api.id" value="#{h @conf['nhk_api.id']}" size="70"></p>
<p>Register your tDiary and get API key.</p>
<a href="http://www2.nhk.or.jp/api/">Go NHK API settings.</a></p>
<h3 class="subtitle">Default Area</h3>
<p><input name="nhk_api.default.area" value="#{h @conf['nhk_api.default.area']}" size="70"></p>
<a href="http://www2.nhk.or.jp/api/">Refer NHK API settings.</a></p>
HTML
end
# Local Variables:
# mode: ruby
# indent-tabs-mode: t
# tab-width: 3
# ruby-indent-level: 3
# End:
# vim: ts=3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment