Skip to content

Instantly share code, notes, and snippets.

@starenka
Created October 8, 2012 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save starenka/3851806 to your computer and use it in GitHub Desktop.
Save starenka/3851806 to your computer and use it in GitHub Desktop.
import urllib
import requests
API_URL = 'http://is.gd/api.php?longurl='
def shorten(uri):
resp = requests.get(API_URL + urllib.quote(uri), timeout=30)
if resp:
return resp.text
else:
return False
with open('links.txt', 'r') as f:
out = []
for one in f.readlines():
one = one.strip().strip('\r\n').strip('\n')
out.append('%s\t%s' % (one, shorten(one)))
with open('shortened.txt', 'w+') as fo:
fo.write('\n'.join(out))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment