NHK Program Search
Stores program information matching the keyword specified in String type data item into a String type data item, and stores its communication log in a String type data item.
2017 (C) Questetra, Inc. (MIT License)
Configs
  • A: Set NHK API KEY *
  • B: Select AREA CODE *
  • C: Select SERVICE ID *
  • D: Select DATE *
  • E: Select SEARCH WORDS CSV *
  • F: Select Access Log *
  • G: Select Match Log *
Script
// Provision of information: NHK

//// == Config & Retrieving ==
// Registered apps in your NHK Program Guide API
// http://api-portal.nhk.or.jp/
var nhkKey = configs.get( "conf_DataIdA" );

// http://api-portal.nhk.or.jp
var nhkArea = data.get( configs.get( "conf_DataIdB" ) ) + "";
var nhkService = data.get( configs.get( "conf_DataIdC" ) ) + "";
 // Synthesis "g1", ETV "e1", BS1 "s1", BS Pre "s3"
var nhkDate = data.get( configs.get( "conf_DataIdD" ) ) + "";
var searchWordsCsv = data.get( configs.get( "conf_DataIdE" ) ) + "";

var dataIdF = configs.get( "conf_DataIdF" );
var dataIdG = configs.get( "conf_DataIdG" );

//// == Calculating ==
var accessLog = "";
var matchLog = "";

/// -- GET program list --
var uri = "http://api.nhk.or.jp/v2/pg/list/";
uri += nhkArea + "/";
uri += nhkService + "/";
uri += nhkDate + ".json?key=";
uri += nhkKey;

// com.questetra.bpms.core.event.scripttask.HttpClientWrapper
// https://www.questetra.com/ja/tour/m2/m230/
// HttpRequestWrapper
var requestMsg = httpClient.begin();

// HttpResponseWrapper
var responseMsg = requestMsg.get( uri );
accessLog += "---GET--- " + responseMsg.getStatusCode() + " " + responseMsg.getCharset() + "\n";
accessLog += responseMsg.getResponseAsString() + "\n\n";

/// -- Word Search --
var responseObj = JSON.parse( responseMsg.getResponseAsString() );
var searchWords = searchWordsCsv.split(",");

var tmp = "";
for (var i = 0; i < responseObj.list[nhkService].length; i ++) { // Bracket notation
  tmp = responseObj.list[nhkService][i].start_time.slice(11, 16) + "\n";
  tmp += responseObj.list[nhkService][i].title + "\n";
  tmp += responseObj.list[nhkService][i].subtitle + "\n";
  tmp += responseObj.list[nhkService][i].content + " ";
  tmp += responseObj.list[nhkService][i].act + "\n";

  for (var j = 0; j < searchWords.length; j ++) {
    if ( tmp.match( searchWords[j] ) ) {
      matchLog += tmp + "\n+++ \n\n";
      break;
    }
  }
}


//// == Data Updating ==
retVal.put( dataIdF, accessLog );
retVal.put( dataIdG, matchLog );

Download

Capture

Notes

  • * Separate multiple keywords with commas

See also

%d bloggers like this: