1

我正在编写一个非常小的程序,我想在我的 RPI 上运行一个 cron 作业。每小时我想检查一个网页的状态。如果状态符合特定标准,我希望它通过电子邮件发送给我。

过去我已经成功地使用了 gmail gem,但是我总是必须提供我的凭据。我对将我的 gmail 凭据存储在文件中感到紧张。有谁知道如何更安全地完成这项任务?

最终目标是我想要在我的收件箱中收到一封电子邮件,告诉我我正在监控的网站上的闸门状态已更改。

这是我到目前为止所拥有的

#!/usr/bin/ruby
require 'open-uri'
require 'nokogiri'


def check_gates
    doc = Nokogiri::HTML(open('http://www.summitatsnoqualmie.com/Mountains/Grooming-Report'))
    gates = {}

    table_rows = doc.xpath('//tr')

    sections = []

    sections.push({:gate => "Elevator", :data => table_rows.select { |tr| tr.inspect.include? "Lower Traverse" }.first})
    sections.push({:gate => "Nash", :data => table_rows.select { |tr| tr.inspect.include? "Upper Traverse" }.first})

    sections.each do |section|
        status_text =  section[:data].element_children.select { |child| child.inspect.include? "grooming_open_status" }.first.inspect
        match = status_text.match(/background-position:\ (\d+)px\ (.\d)+px/)

        gate_down = false

        unless match.nil?
            gate_down = match[1].to_i == 0 and match[2].to_i == 0
        end

        gates[section[:gate]] = gate_down ? "CLOSED" : "OPEN"

    end

    gates
end
4

1 回答 1

1

为您的 Google 帐户生成应用程序专用密码,并将该密码存储在服务器上。

于 2013-11-02T04:46:16.223 回答