From 4507f39dd6532119774626566ffa3cf7bba6533b Mon Sep 17 00:00:00 2001 From: jessykate Date: Sat, 13 Nov 2010 23:49:14 -0500 Subject: [PATCH] merging lib files --- api/lib.py | 22 ++++++++++++++++++++++ frontend/lib.py | 25 ------------------------- 2 files changed, 22 insertions(+), 25 deletions(-) delete mode 100644 frontend/lib.py diff --git a/api/lib.py b/api/lib.py index 70c74eb..bf0243c 100644 --- a/api/lib.py +++ b/api/lib.py @@ -1,6 +1,28 @@ #!/usr/bin/python import re, htmlentitydefs +from settings import BITLY_USER, BITLY_KEY +import urllib2, urllib +try: + import json +except: + import simplejson as json + + +def bitly_shorten(long_url): + # the long_url must contain the protocol + if not long_url.startswith('http://'): + long_url = 'http://' + long_url + base = "http://api.bit.ly/v3/shorten?" + args = { + 'login': BITLY_USER, + 'apiKey': BITLY_KEY, + 'longUrl' : long_url, + } + api_call = base+urllib.urlencode(args) + fp = urllib2.urlopen(api_call) + js = json.loads(fp.read()) + return js['data']['url'] def html_unescape(text): ''' Function by Fredrik Lundh at diff --git a/frontend/lib.py b/frontend/lib.py deleted file mode 100644 index 17bd0be..0000000 --- a/frontend/lib.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/python - -from settings import BITLY_USER, BITLY_KEY -import urllib2, urllib -try: - import json -except: - import simplejson as json - - -def bitly_shorten(long_url): - # the long_url must contain the protocol - if not long_url.startswith('http://'): - long_url = 'http://' + long_url - base = "http://api.bit.ly/v3/shorten?" - args = { - 'login': BITLY_USER, - 'apiKey': BITLY_KEY, - 'longUrl' : long_url, - } - api_call = base+urllib.urlencode(args) - fp = urllib2.urlopen(api_call) - js = json.loads(fp.read()) - return js['data']['url'] -