Created
October 1, 2009 18:44
-
-
Save nathos/199156 to your computer and use it in GitHub Desktop.
Amazon URL stripper
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
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