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:

  1. Install pydelicious
  2. Install Phenny
  3. 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'.*'
  4. Fill in delicious account information in the obvious place.
  5. Start/Restart Phenny and watch posted links appear in delicious.
  6. 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.

4 Responses to “IRC Bot to Post Links to Delicious”

  1. Doug Napoleone Says:

    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)?

  2. Michael Schurter Says:

    @Doug:

    Done! See: http://del.icio.us/pycon

  3. bob torres Says:

    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.

  4. bob torres Says:

    A friend figured it out, and this works:

    http://www.pastebin.ca/949000

Leave a Reply