Created
August 3, 2012 04:12
-
-
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
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
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