Last active
August 29, 2015 14:03
-
-
Save johnpc/0720b90b185b5eb40d48 to your computer and use it in GitHub Desktop.
download google spreadsheet spreadsheet as csv and read through it, emailing someone when the record includes todays date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mail' | |
require 'date' | |
require 'gdata/client' | |
require 'gdata/http' | |
require 'gdata/auth' | |
options = { :address => "smtp.gmail.com", | |
:port => 587, | |
:domain => 'your.host.name', | |
:user_name => '<username>', | |
:password => '<password>', | |
:authentication => 'plain', | |
:enable_starttls_auto => true } | |
Mail.defaults do | |
delivery_method :smtp, options | |
end | |
def get_spreadsheet_csv | |
resource_ID = 'resource_ID_of_your_spreadsheet' | |
client = GData::Client::Spreadsheets.new | |
client.clientlogin('your_email', 'your_pass') | |
test = client.get("https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key="+resource_ID+"&fmcmd&exportFormat=csv") | |
file = File.new("spreadsheet.csv", "wb") | |
file.write test.body | |
file.close | |
end | |
get_spreadsheet_csv | |
File.open("spreadsheet.csv", "r") do |infile| | |
while (line = infile.gets) | |
if line.include? Date.today | |
Mail.deliver do | |
to 'recipient_email' | |
from 'sender_email' | |
subject 'email_subject' | |
body 'email_body' | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment