I want to try and run my code, even if I encounter an error. I'll state where I believe I get the error below and what the error is:
require 'rubygems'
require 'simple_oauth'
require 'cloudsight'
require 'rubygems'
require 'net/http'
require 'uri'
require 'json'
require 'open-uri'
require 'openssl'
require 'hpricot'
#ALCHEMY
file='C:\\Users\\ENTER USERNAME\\Desktop\\cloudsight.txt'
f = File.open(file, "r")
f.each_line {|line|
tstart = 'name"=>"'
tstop = '"'
term = line[/#{tstart}(.*?)#{tstop}/m, 1]
url = 'http://access.alchemyapi.com/calls'
service = '/text/TextGetRankedTaxonomy'
apikey = '?apikey=ENTER ALCHEMY API KEY'
thething = '&text='
termencoded = URI::encode(term)
fullurl = url + service + apikey + thething + termencoded
sleep 1
opener = open(fullurl, 'Accept-Encoding' => '') {|f| f.read }
#print opener
I think I get the error at this point.
lstart = '<label>/'
lstop = '</label>'
label = opener[/#{lstart}(.*?)#{lstop}/m, 1]
sleep 1
cstart = '<score>'
cstop = '</score>'
confidence = opener[/#{cstart}(.*?)#{cstop}/m, 1]
#data = label + ',' + confidence + ',' + line
print label
print confidence
print "\n"
}
This is the error I seem to get:
C:/Ruby21/lib/ruby/2.1.0/uri/common.rb:304:in `escape': undefined method `gsub' for nil:NilClass (NoMethodError)
Any ideas as to how I can pass the error/escape it/ or make a string come up instead?