view bitsyapps/on.py @ 0:159d911ad01c default tip

initial stub for bitsyapps
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 02 Nov 2010 08:05:36 -0700
parents
children
line wrap: on
line source

import os

class BitsyDoc(object):

  # TODO: make this work with tagging

  on = 'on '
  separator = '\n--\n\n'

  def __init__(self, bitsyblog, directory):
    self.bitsyblog = bitsyblog
    self.directory = directory
    assert os.path.exists(directory)

  def __call__(self, blog_entry, url):
    title = blog_entry.title()
    if ':' in title and title.startswith(self.on):
      subject, title = title.split(':', 1)
      subject = subject[len(self.on):].lower()
      full_subject = self.on + subject + ':'

      # XXX single-word subjects, for now

      filename = subject + '.txt'
      filename = os.path.join(self.directory, filename)

      exists = os.path.exists(filename)

      f = file(filename, 'a')
      if exists:
        print >> f, self.separator

      body = blog_entry.body.split(full_subject, 1)[-1].strip()

      print >> f, body
      f.close()