Skip to content

Instantly share code, notes, and snippets.

@nathos
Created October 1, 2009 18:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathos/199156 to your computer and use it in GitHub Desktop.
Save nathos/199156 to your computer and use it in GitHub Desktop.
Amazon URL stripper
affiliate_id = "nathos-20"
ARGF.each do |f|
f = f.scan(/(?:http:\/\/(?:www\.){0,1}amazon\.com(?:\/.*){0,1}(?:\/dp\/|\/gp\/product\/))(.*?)(?:\/.*|$)/i)
shorturl = "http://www.amazon.com/dp/" + f.to_s + "/ref=nosim/" + affiliate_id
if shorturl == ("http://www.amazon.com/dp//ref=nosim/" + affiliate_id)
puts "Not a valid Amazon URL"
else
puts shorturl
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment