Created
February 2, 2012 17:58
-
-
Save mess110/1724874 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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'twitter' | |
help_message = <<HELP_MESSAGE | |
Create a twitter client script that retrieves all the unique http links in the | |
last 100 most recent tweets using a hashtag parameter. The application should | |
be executable from the command line and should print the results to STDOUT. | |
We will run the script by passing it a hashtag e.g. | |
$ ruby twitter_links.rb someHashtag | |
Sample Output: | |
1. http://some.url.test | |
2. http://another.url.test | |
3. http://again.url.test | |
HELP_MESSAGE | |
if ARGV.size != 1 | |
puts help_message | |
exit 1 | |
end | |
# https://dev.twitter.com/docs/api/1/get/search | |
# | |
# parameters: | |
# result_type = recent | |
# include_entities = true (we want twitter to parse urls for us) | |
# rpp = 100 (returning twits per page. max is 100 according to API) | |
all_urls = [] | |
Twitter.search("#" + ARGV[0], :result_type => 'recent', :rpp => 100, :include_entities => true).each do |twit| | |
twit.expanded_urls.each do |url| | |
all_urls << url if not url.nil? | |
end | |
end | |
all_urls.uniq.each_with_index do |url, index| | |
puts (index + 1).to_s + ". " + url | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
so what do you think?