Skip to content

Instantly share code, notes, and snippets.

@giginet
Created December 6, 2011 05:07
Show Gist options
  • Select an option

  • Save giginet/1436839 to your computer and use it in GitHub Desktop.

Select an option

Save giginet/1436839 to your computer and use it in GitHub Desktop.
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