2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GithubへのContribute数を取得する

Last updated at Posted at 2017-12-27

もう一年もおわりですね。
ってことでGithubへのContribute数を取得してみます。

Contribute取得方法

GithubにはAPIが用意されていてcommitの詳細を取得することができます。

以前このAPIは使用して1日のcommit数を集計してツイートするアプリケーションを作成しました。
詳しくはこちらをどうぞ。

ですが、この方法だとprivateリポジトリへのcommitが取れないので今回はスクレイピングします(スクレイピングは自己責任でお願いします。

Contribute数を数えているクラスは下記になります。
gemはnokogiriを使用しています。

require 'nokogiri'
require 'open-uri'

class GithubContributeCount

  def create_tweet_text
    count = count_contribute
    "通算で" + count + "回Githubへコミットしています。https://github.com/yshogo Github contribute count app author shogo yamda"
  end

  private
    def count_contribute
      html = Nokogiri::HTML open 'https://github.com/yshogo'
      text = html.xpath('//h2[@class = "f4 text-normal mb-2"]').first.inner_text
      text.delete! 'in the last year'
      text.delete! 'cobuo'
      text.gsub(/[\r\n]/,"")
    end
end

このクラスを使ってContribute数をTwitterへ投稿するアプリケーションを作成しました。

詳しくは下記のブログに書いたのでご覧ください。

Rubyについてもっと勉強したいな〜

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?