Skip to content

Instantly share code, notes, and snippets.

@smison
Last active November 1, 2017 00:51
Show Gist options
  • Select an option

  • Save smison/82eca6e7f4ff41cd4698 to your computer and use it in GitHub Desktop.

Select an option

Save smison/82eca6e7f4ff41cd4698 to your computer and use it in GitHub Desktop.
Githubにcontributeしていないとメール通知するスクリプト(http://qiita.com/smison/items/8e25c6dd84c64f0711c3)
#! /usr/local/bin/ruby
# === parameters ================================
USER_NAME = 'XXXXX' # Gtihubのユーザ名
MAIL_ADDR_FROM = 'XXXXX@XXXXX' # 通知メールのfrom
MAIL_ADDR_TO = 'XXXXX@XXXXX' # 通知メールのto
# === requires ==================================
require 'nokogiri'
require 'open-uri'
require 'mail'
# === methods ===================================
def last_contribute_date parsed_svg
last_rect_day = parsed_svg.search('rect.day').last
last_rect_day["data-date"]
end
def last_contribute_count parsed_svg
last_rect_day = parsed_svg.search('rect.day').last
last_rect_day["data-count"]
end
def contributed_today? svg
parsed_svg = Nokogiri::HTML(svg)
if last_contribute_date(parsed_svg) != Time.now.strftime('%Y-%m-%d')
return false
else
if last_contribute_count(parsed_svg) == '0'
return false
end
end
true
end
def sendmail from_addr, to_addr, subject, body
mail = Mail.new
mail['from'] = from_addr
mail['to'] = to_addr
mail['subject'] = subject
mail['body'] = body
mail.deliver
end
# === main ======================================
svg = open("https://github.com/users/#{USER_NAME}/contributions")
unless contributed_today?(svg)
sendmail(MAIL_ADDR_FROM,
MAIL_ADDR_TO,
"Github contribution notice",
"You haven't contributed to Github yet today!")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment