IRC Bot to Post Links to Delicious
I lurk in an IRC chatroom with some friends and throughout the course of a day a lot of links are posted.
I wanted to be able to catch up on the links without having to read through the entire channel backlog, so I hacked together a new module for Phenny (a Python IRC bot) which posted the links to a Delicious account. I subscribe to that account via Google Reader, and read through the latest Internet memes at my leisure.
To use my little hack:
- Install pydelicious
- Install Phenny
- copy the following code into a new file:
modules/delicious.py#!/usr/bin/env python """ delicious.py - Automatically post URLs to delicious Author: Michael Schurter, http://michael.susens-schurter.com/ License: Public Domain About: http://inamidst.com/phenny/ """ import re import pydelicious r = re.compile(r'http\S*') def f_delicious(self, origin, match, args): try: matches = r.findall(match.group()) if matches: d = pydelicious.DeliciousAPI('DELICIOUS_USERNAME', 'DELICIOUS_PASSWORD') for url in matches: title = '%s: %s' % (origin.nick, match.group()) if len(title) > 50: title = '%s...' % title[:50] d.posts_add( url=url, description=title, extended=match.group(), # Add custom tags below tags='oggbot oggbot-added-by:%s' % origin.nick ) except: self.msg(origin.sender, 'Oops! Missed that one. Blame schmichael!') f_delicious.rule = r'.*'
- Fill in delicious account information in the obvious place.
- Start/Restart Phenny and watch posted links appear in delicious.
There’s lots of room for improvement in the code, but it works for me!
Sorry for poor tab spacing. I had vim configured for some Drupal hacking and forgot to switch back to 4-space tabs.
October 28th, 2007 at 7:00 pm
Are you planning on going to PyCon 2008?
If you are, would you consider setting this up for the #pycon channel on freenode.net to a custom pycon-2008 group delicious thingie (whatever their groups are called)?
November 1st, 2007 at 1:18 pm
@Doug:
Done! See: http://del.icio.us/pycon
March 19th, 2008 at 9:11 am
Hmmm. Doesn’t seem to work for me with the newest Phenny, and pydelicious:
[11:06:39] TypeError: f_delicious() takes exactly 4 arguments (2 given) (file “/home/veganfreak/bot/phenny/bot.py”, line 182, in call)
I know next to nothing about python, so any help getting this rolling would be much appreciated. Phenny seems to work fine otherwise, though.
March 19th, 2008 at 10:13 am
A friend figured it out, and this works:
http://www.pastebin.ca/949000