2

试图从 CRML 媒体资源中获取 :all (first :item)。使用 Estately RETS 回购。这是我的红宝石示例文件:

require 'rets'

client = Rets::Client.new({
  login_url: 'url',
  username: 'user',
  password: 'password',
  version: 'RETS/1.7.2' 
})

begin
    client.login
rescue => e
    puts 'Error: ' + e.message
    exit!
end

puts 'We connected! Lets get all the photos for a property...'


photos = client.find (:first), {
  search_type: 'Media',
  class: 'Media',
  query: '(MediaModificationTimestamp=2017-04-15+),(MediaType=Image)'
}


photo = open(photo = photos['MediaURL'])
require 'base64'
image = Base64.encode64(photo.read)


File.open('property-1.gif', 'wb') do|f|
  f.write(Base64.decode64(image))
end

puts photos.length.to_s + ' photos saved.'
client.logout

但我只得到一张图片,而不是预期的 26 张。在我得到第一个工作之后,也不确定这是否是检索所有列表的所有图像的最佳方法。以下是有关此问题的更多信息https://github.com/estately/rets/issues/210

4

2 回答 2

1
require 'rets'

client = Rets::Client.new({
  login_url: 'url',
  username: 'username',
  password: 'password',
  version: 'RETS/1.7.2' 
})

begin
    client.login
rescue => e
    puts 'Error: ' + e.message
    exit!
end

puts 'We connected! Lets get all the photos for a property...'


photos = client.find (:all), {
  search_type: 'Media',
  class: 'Media',
  query: '(ResourceRecordKeyNumeric=117562969),(MediaType=Image)'
}

photos.each_with_index do |data, index|
  photo = open(photo = data['MediaURL'])
  puts data['MediaURL']
  require 'base64'
  image = Base64.encode64(photo.read)
  File.open("property-#{index.to_s}.jpg", 'wb') do |f|
    f.write(Base64.decode64(image))
  end
end


puts photos.length.to_s + ' photos saved.'
client.logout
于 2017-04-27T22:50:47.840 回答
0

您可以尝试在查询部分中使用逗号分隔的列表 ID 一次获取多个列表的所有图像。

photos = client.find (:all), {
search_type: 'Media',
  class: 'Media',
  query: '(ResourceRecordKeyNumeric=117562969,117562970,117562971),(MediaType=Image)'
}
于 2017-12-13T08:36:44.870 回答