Skip to content

Instantly share code, notes, and snippets.

@bryanherger
Created August 27, 2016 17:37
Show Gist options
  • Save bryanherger/309f928651a6875c50fe3bfe6bd63b79 to your computer and use it in GitHub Desktop.
Save bryanherger/309f928651a6875c50fe3bfe6bd63b79 to your computer and use it in GitHub Desktop.
Lua CFS script to retrieve sentiment analysis from Haven OnDemand and store in an IDOL document field.
local function isempty(s)
return s == nil or s == ''
end
function handler(document)
local config = get_config("cfs.cfg")
local log = get_log(config, "IndexLogStream")
log:write_line( log_level_error() , "HOD started")
local sentText = document:getFieldValue("DRECONTENT")
-- handle case where content is empty or too short
if isempty(sentText) then
log:write_line( log_level_error() , "HOD finished, empty DRECONTENT")
return true
end
local sentResponse = " ";
f = assert (io.popen ("curl -X POST --form \"text=" .. sentText .. "\" --form \"apikey=XXX\" https://api.havenondemand.com/1/api/sync/analyzesentiment/v1") )
for line in f:lines() do
log:write_line(log_level_error(), line)
sentResponse = sentResponse .. " " .. line;
end
f:close()
document:addField("SENTIMENT", sentResponse)
log:write_line( log_level_error() , "HOD finished: " .. sentResponse)
return true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment