Ruby 是否与Excel数据一起使用以显示在仪表板上?
我正试图从中获得以下代码的示例,对于我的Linux/Ubuntu安装来说,这似乎是一个死话题。我一直在尝试使用mechanize see从公司内部网中获取数据。由于我不够聪明,无法找到解决登录问题的方法,我想我会尝试从excel工作表中输入数据,作为一种解决方法,直到我能够找到mechanize路线。再一次,我不够聪明,无法让提供的代码在Linux上运行,因为我遇到了以下错误: `kqueue=':此平台不支持kqueue EventMachine::Unsupported 如果我从原始源代码中提供的信息理解正确,那么问题是Linux不支持kqueue。OP声明inotify是一个替代方案,但我没有找到一个类似的例子,使用它在小部件中显示Excel 下面是GitHub上显示的代码,希望帮助将其转换为在Linux上工作:Ruby 是否与Excel数据一起使用以显示在仪表板上?,ruby,linux,excel,dashing,roo-gem,Ruby,Linux,Excel,Dashing,Roo Gem,我正试图从中获得以下代码的示例,对于我的Linux/Ubuntu安装来说,这似乎是一个死话题。我一直在尝试使用mechanize see从公司内部网中获取数据。由于我不够聪明,无法找到解决登录问题的方法,我想我会尝试从excel工作表中输入数据,作为一种解决方法,直到我能够找到mechanize路线。再一次,我不够聪明,无法让提供的代码在Linux上运行,因为我遇到了以下错误: `kqueue=':此平台不支持kqueue EventMachine::Unsupported 如果我从原始源代码中
require 'roo'
EM.kqueue = EM.kqueue?
file_path = "#{Dir.pwd}/spreadsheet.xls"
def fetch_spreadsheet_data(path)
s = Roo::Excel.new(path)
send_event('valuation', { current: s.cell(1, 2) })
end
module Handler
def file_modified
fetch_spreadsheet_data(path)
end
end
fetch_spreadsheet_data(file_path)
EM.next_tick do
EM.watch_file(file_path, Handler)
end
好的,因此我能够通过执行以下操作来实现这一点,并在仪表板小部件上显示我的数据: 首先:我将电子表格.xls上传到我的仪表板的根目录 第二:我将/jobs/sample.rb代码替换为:
#!/usr/bin/env ruby
require 'roo'
SCHEDULER.every '2s' do
file_path = "#{Dir.pwd}/spreadsheet.xls"
def fetch_spreadsheet_data(path)
s = Roo::Excel.new(path)
send_event('valuation', { current: s.cell('B',49) })
end
module Handler
def file_modified
fetch_spreadsheet_data(path)
end
end
fetch_spreadsheet_data(file_path)
end
第三:确保/widgets/number位于仪表板中,这是示例安装的一部分
第四:将以下代码添加到/dashboards/sample.erb文件中这也是示例安装的一部分
<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-id="valuation" data-view="Number" data-title="Current Valuation" data-prefix="$"></div>
</li>
我曾经帮助我更好地理解Roo是如何工作的。我通过更改我的值并将电子表格.xls重新上传到服务器来测试我的小部件,并在我的仪表板上看到即时更改
希望这对某人有所帮助,我仍然在寻找帮助,通过抓取数据来自动化这个过程。参考。感谢分享此代码示例。我没有设法使它在我的环境中发挥作用,但经过一些努力,我终于想出了一些可行的办法——至少对我来说是这样 本周之前我从未使用过Ruby,所以这段代码可能有点糟糕。请接受道歉 -克里斯托夫
require 'roo'
require 'rubygems'
require 'rb-inotify'
# Implement INotify::Notifier.watch as described here:
# https://www.go4expert.com/articles/track-file-changes-ruby-inotify-t30264/
file_path = "#{Dir.pwd}/datasheet.csv"
def fetch_spreadsheet_data(path)
s = Roo::CSV.new(path)
send_event('csvdata', { value: s.cell(1, 1) })
end
SCHEDULER.every '5s' do
notifier = INotify::Notifier.new
notifier.watch(file_path, :modify) do |event|
event.flags.each do |flag|
## convert to string
flag = flag.to_s
puts case flag
when 'modify' then fetch_spreadsheet_data(file_path)
end
end
end
## loop, wait for events from inotify
notifier.process
end