0

当我使用 Kiba ELT 时,我遵循了 YouTube 中的教程以及所有者提供的教程。然而,我收到了这个错误:

bitlasoft@Bitlasoft-TS-22:~/test01$ bundle exec kiba movies.etl
{
    "title: Blade Runner" => "title: Minority Report"
}
/home/bitlasoft/.rvm/gems/ruby-2.2.2/gems/themoviedb-1.0.1/lib/themoviedb/api.rb:37:in `set_response': Tmdb::InvalidApiKeyError (Tmdb::InvalidApiKeyError)
    from /home/bitlasoft/.rvm/gems/ruby-2.2.2/gems/themoviedb-1.0.1/lib/themoviedb/search.rb:75:in `fetch_response'
    from /home/bitlasoft/.rvm/gems/ruby-2.2.2/gems/themoviedb-1.0.1/lib/themoviedb/search.rb:60:in `fetch'
    from /home/bitlasoft/.rvm/gems/ruby-2.2.2/gems/themoviedb-1.0.1/lib/themoviedb/resource.rb:41:in `search'
    from /home/bitlasoft/test01/common.rb:30:in `process'
    from /home/bitlasoft/.rvm/gems/ruby-2.2.2/gems/kiba-0.6.1/lib/kiba/runner.rb:35:in `block (3 levels) in process_rows'
    from /home/bitlasoft/.rvm/gems/ruby-2.2.2/gems/kiba-0.6.1/lib/kiba/runner.rb:34:in `each'
    from /home/bitlasoft/.rvm/gems/ruby-2.2.2/gems/kiba-0.6.1/lib/kiba/runner.rb:34:in `block (2 levels) in process_rows'
    from /home/bitlasoft/test01/common.rb:12:in `block in each'
    from /home/bitlasoft/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/csv.rb:1739:in `each'
    from /home/bitlasoft/test01/common.rb:11:in `each'
    from /home/bitlasoft/.rvm/gems/ruby-2.2.2/gems/kiba-0.6.1/lib/kiba/runner.rb:33:in `block in process_rows'
    from /home/bitlasoft/.rvm/gems/ruby-2.2.2/gems/kiba-0.6.1/lib/kiba/runner.rb:32:in `each'
    from /home/bitlasoft/.rvm/gems/ruby-2.2.2/gems/kiba-0.6.1/lib/kiba/runner.rb:32:in `process_rows'
    from /home/bitlasoft/.rvm/gems/ruby-2.2.2/gems/kiba-0.6.1/lib/kiba/runner.rb:13:in `run'
    from /home/bitlasoft/.rvm/gems/ruby-2.2.2/gems/kiba-0.6.1/lib/kiba/cli.rb:13:in `run'
    from /home/bitlasoft/.rvm/gems/ruby-2.2.2/gems/kiba-0.6.1/bin/kiba:5:in `<top (required)>'
    from /home/bitlasoft/.rvm/gems/ruby-2.2.2/bin/kiba:23:in `load'
    from /home/bitlasoft/.rvm/gems/ruby-2.2.2/bin/kiba:23:in `<main>'
    from /home/bitlasoft/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `eval'
    from /home/bitlasoft/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `<main>'
bitlasoft@Bitlasoft-TS-22:~/test01$  

这是我的 movies.etl 和 common.rb 配置:

 require_relative 'common'
api_key = IO.read('.themoviedb')
source CSVSource, filename: 'movies.csv'        
limit ENV['LIMIT']
show_me!
transform MovieDBlookup,
api_key: api_key,
title_field: 'title'
show_me!

require 'csv'
 require 'awesome_print'

 class CSVSource 
    def initialize(filename:)   
    @filename = filename
        end

  def each
    csv = CSV.open(@filename, headers: true)
    csv.each do |row|
    yield(row.to_hash)

    end 

csv.close

    end
        end 

  require 'themoviedb'

class MovieDBlookup
 def initialize(api_key:, title_field:)
 @title_field = title_field
 Tmdb::Api.key(api_key)
    end

 def process(row)
 movie = Tmdb::Movie.find(row[@title_field]).first
 row[:vote_average] = movie.vote_average
 row[:vote_count] = movie.vote_count
 row
    end 
    end

def show_me!    
    transform do |row|
    ap row
    row
    end 
    end

def limit(x)
x = Integer(x || -1)
return if x == -1
   transform do |row|
   @counter ||= 0 
   @counter += 1
   abort("stopping....")if @counter >= x
   row
    end 
    end 
4

1 回答 1

1

(这里是 Kiba 所有者)-您得到的错误不是 Kiba 特定的;您为themoviedb提供的 API 密钥似乎无效。您是否在此处注册了电影数据库,提供的 API 密钥是否已复制粘贴到您正在加载的文件中(.themoviedb)?

我能想到的一个问题是你在那个文件中有一个换行符(回车/换行),在这种情况下,也许只是调用api_key = IO.read('.themoviedb').strip会有所帮助。

同样,这不是 Kiba 特有的,但希望这会有所帮助!

于 2016-11-15T18:51:57.993 回答