Skip to content

Instantly share code, notes, and snippets.

@d-sea
Created November 9, 2017 02:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d-sea/f236e8237f1dab553b5f680eaa17ad5f to your computer and use it in GitHub Desktop.
Save d-sea/f236e8237f1dab553b5f680eaa17ad5f to your computer and use it in GitHub Desktop.
require 'date'
require 'mail'
require 'json'
notify_term = 5
File.open("item-list.json", "r+") do |f|
f.each_line { |line|
item = JSON.parse(line)
case item["shop"]
when "Amazon"
shop_url = "https://www.amazon.co.jp/"
when "Rakuten"
shop_url = "https://www.rakuten.co.jp/"
when "Yodobashi"
shop_url = "http://yodobashi.com/"
when "スーパー"
shop_url = "(自分で買いに行ってね)"
else
shop_url = "(自分で調べてね)"
end
# Mail Settings
mail = Mail.new do
from 'from@example.com'
to 'to@example.com'
subject '[オキニ] ' + item["name"] + ' 購入時期です'
body item["name"] + ' を ' + item["shop"] + ' ' + shop_url + ' で買ってね。'
end
options = { :address => 'smtp.gmail.com',
:port => 587,
:domain => 'gmail.com',
:user_name => 'from@example.com',
:password => 'PUT YOUR PASSWORD',
:authentication => :plain,
:enable_starttls_auto => true }
mail.charset = 'utf-8'
mail.delivery_method(:smtp, options)
# Send Mail
if Date.parse(item["updated_date"]) + item["cycle"] - notify_term < Date.today
mail.deliver
else
p "購入時期に該当しませんでした。 " + item["name"]
end
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment