Skip to content

Instantly share code, notes, and snippets.

@vzvu3k6k
Last active May 14, 2016 06:34
Show Gist options
  • Save vzvu3k6k/e3832e3a5480e8d8a90b5a3edad429c1 to your computer and use it in GitHub Desktop.
Save vzvu3k6k/e3832e3a5480e8d8a90b5a3edad429c1 to your computer and use it in GitHub Desktop.
ATNDの参加者リストからTwitter IDを取り出す
$ bundle install
$ bundle exec -- ./list_twitter_ids.rb atnd_url
source 'https://rubygems.org'
gem 'oga'
GEM
remote: https://rubygems.org/
specs:
ansi (1.5.0)
ast (2.2.0)
oga (2.2)
ast
ruby-ll (~> 2.1)
ruby-ll (2.1.2)
ansi
ast
PLATFORMS
ruby
DEPENDENCIES
oga
BUNDLED WITH
1.11.2
#!/usr/bin/env ruby
# License: CC0
require "oga"
require "open-uri"
require "uri"
if ARGV.size != 1
abort "Usage: #{File.basename(__FILE__)} [atnd URL]"
end
event_uri = ARGV.shift
event_page = Oga.parse_html(open(event_uri).read)
event_page.css('#members-join a[href^="/users/"]').each {|i|
user_uri = URI.join("https://atnd.org/", i.get("href"))
if user_uri.host != "atnd.org"
raise "#{user_uri} is not under atnd.org."
end
sleep 1
user_page = Oga.parse_html(open(user_uri).read)
tw_link = user_page.at_css(
'#users-show-info a[href^="http://twitter.com/"],' +
'#users-show-info a[href^="https://twitter.com/"]'
)
if tw_link
puts URI(tw_link.get("href").sub("/#!", "")).path.split("/")[1]
else
warn "Twitter ID is not found in #{user_uri} (#{user_page.at_css("#users h1").text.strip})."
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment