Last active
August 29, 2015 14:19
-
-
Save robmiller/ce072c37df914adec0ac to your computer and use it in GitHub Desktop.
Ruby one-liner to replace URLs in a CSV with their bitly-shortened versions. Assumes you have a bit.ly account
This file contains 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
$ gem install bitly | |
$ export BITLY_USERNAME="your bit.ly username" BITLY_API_KEY="your bit.ly API key" | |
$ ruby -rcsv -rbitly -e 'b = Bitly.new(ENV["BITLY_USERNAME"], ENV["BITLY_API_KEY"]); CSV.filter { |r| r.each { |f| f.replace b.shorten(f).short_url if f =~ /^https?:/ } }' urls.csv > urls.shortened.csv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment