diff --git a/shorten.py b/shorten.py new file mode 100644 index 0000000..b616cf2 --- /dev/null +++ b/shorten.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +""" +shorten.py - URL Shorten Module +Copyright 2013, sfan5 +""" +import urllib + +def shorten(phenny, input): + arg = input.group(2) + if not arg: + arg = "" # Function continues and prints Help Message + arg = arg.split(' ') + if len(arg) < 2: + phenny.reply("Give me an url shorten service and an address") + return phenny.reply("Supported Services: is.gd, v.gd") + else: + if arg[0].lower() == "is.gd": + p = urllib.urlencode({'format' :"simple", 'url': arg[1]}) + try: + u = urllib.urlopen("http://is.gd/create.php?%s" % p) + return phenny.reply(u.read()) + except: + return phenny.reply("Problems accessing is.gd, please try a different Service") + if arg[0].lower() == "v.gd": + p = urllib.urlencode({'format' :"simple", 'url': arg[1]}) + try: + u = urllib.urlopen("http://v.gd/create.php?%s" % p) + return phenny.reply(u.read()) + except: + return phenny.reply("Problems accessing v.gd, please try a different Service") + return phenny.reply("Unknown Service") + + +shorten.commands = ['shorten','sh'] +shorten.thread = True + +if __name__ == '__main__': + print __doc__