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
- Goo.gl URL shortener by aabele 2 years, 7 months ago
- Create short URL redirects for site urls. by matt.geek.nz 4 years, 3 months ago
- Basic Auth Middleware by joshsharp 1 year, 11 months ago
- view by view basic authentication decorator by Scanner 6 years ago
- Saving passwords for other services (semi-)securely in a database by equanimity 4 years, 3 months ago
Comments
Shouldn't it be: settings.BITLY_USERNAME ?
For more advanced shortening you can check this out: https://github.com/jcfigueiredo/python-bitly
#
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.
#