#!/usr/bin/env python # -*- coding: utf-8 -*- # __ ___ ___ __ __ # |__) | |__ |__ / \ / \ # | | |___ | \__/ \__/ # # - - - - - - - - - - - - - - # Title : Shorten URLs in Python with CoinURL # Site : http://piefoo.webs.com # - - - - - - - - - - - - - - # You need a CoinURL account for this to work! # You can get one here: # https://coinurl.com/index.php?ref=21f7ecbf9977416d430ac1ea7d26e005 # - - - - - - - - - - - - - - import urllib import urllib2 def get_coinurl(uuid, url): url = urllib2.quote(url.encode("utf8")) result = urllib.urlopen('https://coinurl.com/api.php?uuid={0}&url={1}'.format(uuid, url)).read() if result != 'error': return result # You can find your UUID @ https://coinurl.com/profile.php uuid = 'UUID Here' # Shorten only one URL url = raw_input('URL to shorten: ') coinurl = get_coinurl(uuid, url) if coinurl: print 'Success:', coinurl else: print 'Failed:', url # Shorten a list of URLs in a file ''' with open('urls_to_shorten.txt') as f: coinurls = '' for line in f.readlines(): url = line.strip() coinurl = get_coinurl(uuid, url) if coinurl: print 'Success:', coinurl coinurls += coinurl+'\n' else: print 'Failed:', url # Saves all CoinURLs with open('output.txt', 'w') as f: f.write(coinurls) '''