Skip to content

Commit

Permalink
removed api keys
Browse files Browse the repository at this point in the history
  • Loading branch information
djpidol committed Sep 18, 2015
1 parent 5f1255d commit b8c5ff5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 62 deletions.
52 changes: 18 additions & 34 deletions cadena SER.rb
Original file line number Diff line number Diff line change
@@ -1,52 +1,32 @@
# thought for the day rss -> speech to text
# Cadena Ser rss -> speech to text
# https://twitter.com/DJPDeveloper
#
# tested with ruby 2.0.0 y 2.1.1

# encoding: UTF-8
require 'rexml/document'
require 'open-uri'
require 'uri'
require 'net/http'
require 'json'
#require 'rss'
# require 'open-uri'

# this is a script to show how to connect to IdolOnDemand as a rest service
# and apply speech to text analysis

# insert your api_key here, you can request by registering at
# https://www.idolondemand.com/signup.html
# and then go to Tools->Account->Manage Your API Keys
$api_key= "afb65d0b-4658-4ffe-9485-5e14b4331ab7"
$api_key= "xxx"

# how long to wait between status requests
$status_wait= 30
# fuente SER
$lol = 'http://urotrosfiles.media.streamtheworld.com/otrosfiles/podcasts/571.xml'

$media_items = [[:title => 'Andrea Levy: "Lo más importante es que la situación se reconduzca"',
:link => "http://sdmedia.playser.cadenaser.com/Podcast/2015/7/6/000WB0607820150706013923.mp3"],
[:title => 'Jordi Sevilla: "El resultado del referéndum no tiene vuelta de hoja"',
:link => "http://sdmedia.playser.cadenaser.com/Podcast/2015/7/6/000WB0607820150706013756.mp3"],
[:title => 'Alberto Garzón: "No se puede construir una Unión Europea en contra de la gente"',
:link => "http://sdmedia.playser.cadenaser.com/Podcast/2015/7/6/000WB0607820150706013228.mp3"],
[:title => 'Miguel Urbán: "Lo importante al final es lo que dice y construye la gente"',
:link => "http://sdmedia.playser.cadenaser.com/Podcast/2015/7/6/000WB0607820150706012913.mp3"]]
# language for Speech analisis
$audio_language="es-ES"
# language for Sentiment analisis
$sentiment_language="spa"

# setup proxy
$proxy_addr = 'proxy.gre.hp.com'
$proxy_port = 8080


##########
## get RSS feed
#def get_media_items(url)
# uri = URI.parse(url)
# puts "Retrieving RSS #{$rss_source}"
# feed = RSS::Parser.parse(uri.open(:proxy => "http://"+$proxy_host+":"+$proxy_port+"/"))
# return feed.items
#end

##########
## wait for a REST request
def wait_on_status(jobid)
Expand Down Expand Up @@ -103,10 +83,10 @@ def speech_analysis(url)

##########
## Format output
def analyze(item)
puts "Analysing Item #{item[0][:title]}"
puts "URL #{item[0][:link]}"
sa_content = speech_analysis(item[0][:link])[0]['result']['document'][0]['content']
def analyze(title,guid)
puts "Analysing Item #{title}"
puts "URL #{guid}"
sa_content = speech_analysis(guid)[0]['result']['document'][0]['content']
# serialize to debug the data structure
#File.open('sa_res', 'w+') do |f|
# Marshal.dump(sa_res, f)
Expand All @@ -120,6 +100,10 @@ def analyze(item)
#Net::HTTP.new('api.idolondemand.com', nil, $proxy_addr, $proxy_port).start { |http|
# always proxy via your.proxy.addr:8080
puts "Get media Items from RSS feed and analyze them voice->text->sentiment"
$media_items.each {|item|
analyze(item)}
#}
##########
## get RSS feed
puts "Retrieving RSS #{$lol}"
REXML::Document.new(open(URI.parse($lol))).elements.
each('rss/channel/item') {|item|
analyze(item.elements['title'].text,
item.elements['guid'].text)}
54 changes: 26 additions & 28 deletions thought_for_the_day.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
#
# tested with ruby 2.0.0 y 2.1.1

require 'rexml/document'
require 'open-uri'
require 'uri'
require 'net/http'
require 'json'
require 'rss'
# require 'open-uri'

# this is a script to show how to connect to IdolOnDemand as a rest service
Expand All @@ -14,35 +16,28 @@
# insert your api_key here, you can request by registering at
# https://www.idolondemand.com/signup.html
# and then go to Tools->Account->Manage Your API Keys
$api_key= "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
$api_key= "xxx"

# how long to wait between status requests
$status_wait= 10
$status_wait= 30
# fuente RSS
$rss_source='http://downloads.bbc.co.uk/podcasts/radio4/thought/rss.xml'
#$rss_source='http://downloads.bbc.co.uk/podcasts/radio4/thought/rss.xml'
$rss_source='http://www.bbc.co.uk/programmes/p00szxv6/episodes/downloads.rss'
# language for Speech analisis
$audio_language="en-GB"
# language for Sentiment analisis
$sentiment_language="eng"

##########
## get RSS feed
def get_media_items(url)
puts "Retrieving RSS #{$rss_source}"
feed = RSS::Parser.parse(open(url))
return feed.items
end

##########
## wait for a REST request
def wait_on_status(jobid)
uri = URI("https://api.idolondemand.com/1/job/status/" + jobid)
uri = URI("http://api.idolondemand.com/1/job/status/" + jobid)
uri.query = URI.encode_www_form(:apikey => $api_key)
res = Net::HTTP.get_response(uri)
res = Net::HTTP.get_response(uri, p_addr = $proxy_host, p_port = $proxy_port)
obj = JSON.parse(res.body)

if obj['status'] == 'queued'
#puts "job [#{jobid}] #{obj['status']}, waiting #{$status_wait} seconds"
puts "job [#{jobid}] #{obj['status']}, waiting #{$status_wait} seconds"
sleep($status_wait)
wait_on_status(jobid)
end
Expand All @@ -52,19 +47,19 @@ def wait_on_status(jobid)
## retrieve results of a job
def job_results(jobid)
wait_on_status(jobid)
#puts "Retrieving results for job [#{jobid}]"
uri = URI("https://api.idolondemand.com/1/job/result/" + jobid)
puts "Retrieving results for job [#{jobid}]"
uri = URI("http://api.idolondemand.com/1/job/result/" + jobid)
uri.query = URI.encode_www_form(:apikey => $api_key)
res = Net::HTTP.get_response(uri)
res = Net::HTTP.get_response(uri, p_addr = $proxy_host, p_port = $proxy_port)
return JSON.parse(res.body)['actions']
end

##########
## POST a new job and wait for results
def iod_request (api, params)
uri = URI("https://api.idolondemand.com/1/api/async/#{api}/v1")
uri = URI("http://api.idolondemand.com/1/api/async/#{api}/v1")
uri.query = URI.encode_www_form(params)
res = Net::HTTP.get_response(uri)
res = Net::HTTP.get_response(uri, p_addr = $proxy_host, p_port = $proxy_port)
jobid = JSON.parse(res.body)['jobID']
puts "Post request jobid [#{jobid}]"
return job_results(jobid)
Expand All @@ -86,10 +81,10 @@ def speech_analysis(url)

##########
## Format output
def analyze(item)
puts "Analysing #{item.title}"
puts "URL #{item.link}"
sa_content = speech_analysis(item.link)[0]['result']['document'][0]['content']
def analyze(title,link)
puts "Analysing Item #{title}"
puts "URL #{link}"
sa_content = speech_analysis(link)[0]['result']['document'][0]['content']
# serialize to debug the data structure
#File.open('sa_res', 'w+') do |f|
# Marshal.dump(sa_res, f)
Expand All @@ -101,7 +96,10 @@ def analyze(item)
##########
# main starts here
# request RSS y send each item for speech analysis and sentiment
get_media_items($rss_source).each {|item|
analyze(item)}
# just do first one for testing
#analyze(get_media_items($rss_source)[0])
puts "Get media Items from RSS feed and analyze them voice->text->sentiment"
## get RSS feed
puts "Retrieving RSS #{$rss_source}"
REXML::Document.new(open(URI.parse($rss_source))).elements.
each('rss/channel/item') {|item|
analyze(item.elements['title'].text,
item.elements['link'].text)}

0 comments on commit b8c5ff5

Please sign in to comment.