Skip to content

Instantly share code, notes, and snippets.

@naoty
Created June 2, 2012 16:18
Show Gist options
  • Save naoty/2859031 to your computer and use it in GitHub Desktop.
Save naoty/2859031 to your computer and use it in GitHub Desktop.
「#minatork01 gist.github.com -rt」で検索した結果からURLを展開・抽出
@naoty_k https://gist.github.com/2859031
@june29 https://gist.github.com/2856957
@Kirika_K2 https://gist.github.com/2856695
@r7kamura https://gist.github.com/2856841
@sugamasao https://gist.github.com/2856811
@naoty_k http://gist.github.com/2856817
@kei_s https://gist.github.com/2856767
@tdtds https://gist.github.com/2856767
@ymorimo https://gist.github.com/2856767
@nari3 https://gist.github.com/2856773
@ppworks https://gist.github.com/2856772
@netwillnet https://gist.github.com/2856690
@takai https://gist.github.com/2856693
@bash0C7 https://gist.github.com/2856738
@ppworks https://gist.github.com/2856702
require 'net/http'
require 'url_expander'
require 'pry'
query = 'minatork01+gist.github.com+-rt'
Net::HTTP.start('search.twitter.com') do |http|
response = http.get('/search.json?q=' + query)
json = JSON.parse(response.body)
results = json['results']
results.each do |result|
user = result['from_user']
tweet = result['text']
url = tweet.slice(/https?:\/\/t\.co\/\w+/)
next if url.nil?
url = url.gsub(/https/, 'http')
expanded_url = UrlExpander::Client.expand(url)
puts "@#{user}\t#{expanded_url}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment