13 February 2006 ~ 1 Comment

TinyURL API

I was working on my IRC bot again tonight, and added some TinyURL functionality to it.

First, after parsing the command line, it looks for something that looks like a URL:

elif cmd == "tiny":
if cmdline[1].startswith("http://"):
bigurl = cmdline[1]

Next I just used a quick urllib call to grab the new URL and print the results back to the channel:

apiurl = "http://tinyurl.com/api-create.php?url="
tinyurl = urllib.urlopen(apiurl + bigurl).read()
self.msg(channel, "%s: %s" % (user, tinyurl))

Although it could definitely use some beter URL checking to make sure they are valid, it seems to work.

One Response to “TinyURL API”


Leave a Reply