Another version of blather

    And while I'm thinking of all things blather, I've been meaning to post this new version of the blather code for a week or two. This version is just a small refactor which allows for random other python scripts to import blather.py and put messages into the stream of messages to be posted online.

    You can find the source here. A sample program to place messages into the blather stream is:

      #!/usr/bin/python
      
      import feedparser
      import os
      import shelve
      import sys
      
      plugins_dir = '%s/plugins' % os.getcwd()
      print 'Appending %s to module path' % plugins_dir
      sys.path.append(plugins_dir)
      import blather
      
      data = shelve.open('fetchshared.slf', writeback=True)
      ds = blather.DataStore()
      
      changed = False
      for feed in data['feeds']:
        data.setdefault('guids', {})
        data['guids'].setdefault(feed, [])
      
        print
        print 'Fetching %s' % feed
        d = feedparser.parse(feed)
      
        for ent in d.entries:
          if ent.guid not in data['guids'][feed]:
            post = ('Mikal shared: <a href="%s">%s</a>'
                    %(ent.link, ent.title))
            print post
            ds.AddMessage(post)
            data['guids'][feed].append(ent.guid)
            changed = True
      
      if changed:
        ds.Save()
      data.close()
      


    Too easy.

    Tags for this post: blather(S)

posted at: 00:50 | path: /blather | permanent link to this entry



    Add a comment to this post:

    Your name:

    Your email: Email me new comments on this post
      (Your email will not be published on this site, and will only be used to contact you directly with a reply to your comment if needed. Oh, and we'll use it to send you new comments on this post it you selected that checkbox.)


    Your website:

    Comments:


    Because of excessive load, this site is generated statically every several hours. Therefore, your comment may take some time to appear here. Unless you get an error message when you click the select button below, then all is normal and the comment will appear in due course. If you want you can checkout all recently approved comments while your waiting.