$ bundle install
$ bundle exec -- ./list_twitter_ids.rb atnd_url
Last active
May 14, 2016 06:34
-
-
Save vzvu3k6k/e3832e3a5480e8d8a90b5a3edad429c1 to your computer and use it in GitHub Desktop.
ATNDの参加者リストからTwitter IDを取り出す
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
source 'https://rubygems.org' | |
gem 'oga' |
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
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 |
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
#!/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