Last active
December 27, 2017 08:30
-
-
Save s4kr4/4faf4dac410f94a4b6bae3b7af11ae2f to your computer and use it in GitHub Desktop.
日毎のContributions数をCSV形式で取得するやつ
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 '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