Bit.ly url shortener

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
from django.conf import settings
from urllib import urlencode
from urllib2 import urlopen

def shorten_url(long_url):
     username = settings['BITLY_USERNAME']
     password = settings['BITLY_PASSWORD']
     bitly_url = "http://api.bit.ly/v3/shorten?login={0}&apiKey={1}&longUrl={2}&format=txt"
     req_url = urlencode(bitly_url.format(username, password, long_url)
     short_url = urlopen(req_url).read()
     return short_url

More like this

  1. Goo.gl URL shortener by aabele 2 years, 7 months ago
  2. Create short URL redirects for site urls. by matt.geek.nz 4 years, 3 months ago
  3. Basic Auth Middleware by joshsharp 1 year, 11 months ago
  4. view by view basic authentication decorator by Scanner 6 years ago
  5. Saving passwords for other services (semi-)securely in a database by equanimity 4 years, 3 months ago

Comments

rix (on November 29, 2010):

Shouldn't it be: settings.BITLY_USERNAME ?

For more advanced shortening you can check this out: https://github.com/jcfigueiredo/python-bitly

#

AmparoNichols (on January 3, 2012):

Don't have a lot of cash to buy a house? Don't worry, because this is possible to receive the mortgage loans to work out such problems. Hence get a small business loan to buy everything you need.

#

(Forgotten your password?)