Skip to content

Instantly share code, notes, and snippets.

@s4kr4
Last active December 27, 2017 08:30
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 s4kr4/4faf4dac410f94a4b6bae3b7af11ae2f to your computer and use it in GitHub Desktop.
Save s4kr4/4faf4dac410f94a4b6bae3b7af11ae2f to your computer and use it in GitHub Desktop.
日毎のContributions数をCSV形式で取得するやつ
require 'no_proxy_fix'
require 'open-uri'
require 'oga'
base_uri = "https://github.com/s4kr4"
html = open(base_uri) do |f|
f.read
end
doc = Oga.parse_html(html)
# Contributions calendar 1週間分取得
doc.xpath('//*[@class="js-calendar-graph-svg"]/g/g').each do |node|
date_line = ''
count_line = ''
# 1日分ずつ処理
node.children.each do |rect|
next unless rect.is_a?(Oga::XML::Element)
date = rect.get('data-date')
count = rect.get('data-count')
date_line << date
count_line << count
if (Date.parse(date).wday != 6)
# 各曜日の間を','でつなぐ
date_line << ','
count_line << ','
end
end
# 1週間分のデータを出力
puts date_line
puts count_line
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment