# adcrun.ch Link Shortener v 1 by GoldenGod
#
#
# Return short link from adcrun.ch
#
# Get you key and uid from http://adcrun.ch/tools.php?api and put in KEY and
# UID variables (lines 15 and 16)
#
# Usage: python adcrunch.py http://example.com
#
# If you like my script please sing up with my referral: http://adcrun.ch/?r=1370
#!/usr/bin/env python
# -*- coding: utf-8 -*-
KEY = ''
UID = ''
import sys
import urllib
import urllib2
import re
class adcrunch:
def __init__(self, key, uid):
self.key = key
self.uid = uid
def short(self, url, advert_type='int'):
# advert_type = 'banner'
# print url
api_url = 'http://adcrun.ch/api.php'
user_agent = 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1'
values = ({'key' : self.key,
'uid' : self.uid,
'adtype' : advert_type})
headers = {'User-Agent' : user_agent}
data = urllib.urlencode(values)
# print data
full_url = api_url + '?' + data + '&url=' + url
# print full_url
req = urllib2.Request(full_url, headers=headers)
response = urllib2.urlopen(req)
source = response.read()
response.close()
# print source
prog = re.compile('(https?://adcrun.ch/(?!favicon)[-a-zA-Z0-9@:%_\+.~#//=]+|error|Please enter a valid URL)')
short_url = prog.findall(source)
# print short_url
if short_url[0] == 'error':
return 'Wrong Key or Id', 1
elif short_url[0] == 'Please enter a valid URL':
return 'Please enter a valid URL (did you forget to add "http://"?)', 2
elif short_url[0] == '':
return 'Unknown error', 3
else:
return short_url[0], 0 # Everything OK
if __name__ == '__main__':
#Start Program
print 'adcrun.ch Link Shortener v 1 by GoldenGod\n'
# url = 'http://www.example.com'
if len(sys.argv) > 1:
if KEY == '' or UID == '':
print 'You must set your KEY and UID first (line 15 and 16)'
print 'you can find it here: http://adcrun.ch/tools.php?api'
print
url = sys.argv[-1]
ls = adcrunch(KEY, UID)
short_link, status = ls.short(url, advert_type='int')
# If you want banner set: advert_type='banner'
if status == 0:
print 'Shortened link:\n', short_link
else:
print 'Error:\t', short_link, '\nError code:\t', status
else:
print '%s <url>\n\n' % (sys.argv[0])
print 'You must provide proper url adress (with "http://")'
print
print 'Usage:'
print 'python adcrunch.py http://www.example.com'
print '\nIf you like my script please sing up with my referral: ' \
'http://adcrun.ch/?r=1370'
# raw_input('PRESS ENTER TO EXIT')
sys.exit()