Created
December 6, 2011 05:07
-
-
Save giginet/1436839 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 'open-uri' | |
| require 'rubygems' | |
| require 'json' | |
| require 'hatenabm' | |
| GITHUB_USERNAME = 'giginet' | |
| BITBUCKET_USERNAME = 'giginet' | |
| HATENA_USERNAME = 'gigi-net' | |
| HATENA_PASSWORD = '********' | |
| GITHUB_API_BASE = 'https://api.github.com' | |
| GITHUB_API_PATH = "/users/#{GITHUB_USERNAME}/watched" | |
| class RepoBookmarker | |
| """ | |
| Add watching repositories on github to Hatena Bookmark. | |
| """ | |
| def initialize(username, password) | |
| @hbm = HatenaBM.new( | |
| :user => username, | |
| :pass => password | |
| ) | |
| end | |
| def post_from_github | |
| open("#{GITHUB_API_BASE}#{GITHUB_API_PATH}").each do |f| | |
| repos = f | |
| repos = JSON.parse(repos) | |
| repos.each do |repo| | |
| url = repo['html_url'] | |
| r = Regexp.new('https:\/\/github.com\/([^\/]+)\/.*') | |
| username = r.match(url).captures.first | |
| next if username == GITHUB_USERNAME # ignore own repository. | |
| tags = [repo['language'], 'github'] | |
| break if !post url, tags | |
| end | |
| end | |
| end | |
| def post(url, tags) | |
| tags.map! { |tag| | |
| "[#{tag}]" | |
| } | |
| comment = tags.join | |
| begin | |
| @hbm.post( | |
| :link => url, | |
| :summary => comment | |
| ) | |
| return true | |
| rescue | |
| puts 'Auth Error' | |
| return false | |
| end | |
| end | |
| end | |
| bm = RepoBookmarker.new(HATENA_USERNAME, HATENA_PASSWORD) | |
| bm.post_from_github |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment