Skip to content

Instantly share code, notes, and snippets.

@ttscoff
Created August 3, 2012 04:12
Show Gist options
  • Save ttscoff/3244257 to your computer and use it in GitHub Desktop.
Save ttscoff/3244257 to your computer and use it in GitHub Desktop.
Very partial code for parsing out campl.us urls and finding source image url
require 'net/http'
# in the main tweet parser. tweet_text is the status.text string
# match short campl.us urls:
if tweet_text =~ /\((http:\/\/campl.us\/\w+?)\)/
picurl = $1
# grab the source and parse out the full size image url
final_url = get_body(picurl).match(/"(http:\/\/pics.campl.us\/f\/c\/.+?)"/)
return false if final_url.nil?
# do what you want with it...
end
# function to pull the source page of the url
def get_body(sourceurl)
url = URI.parse(sourceurl)
host, port = url.host, url.port if url.host && url.port
req = Net::HTTP::Get.new(url.path)
res = Net::HTTP.start(host, port) {|http| http.request(req) }
return res.body
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment