0
|
1 import os
|
|
2
|
|
3 class BitsyDoc(object):
|
|
4
|
|
5 # TODO: make this work with tagging
|
|
6
|
|
7 on = 'on '
|
|
8 separator = '\n--\n\n'
|
|
9
|
|
10 def __init__(self, bitsyblog, directory):
|
|
11 self.bitsyblog = bitsyblog
|
|
12 self.directory = directory
|
|
13 assert os.path.exists(directory)
|
|
14
|
|
15 def __call__(self, blog_entry, url):
|
|
16 title = blog_entry.title()
|
|
17 if ':' in title and title.startswith(self.on):
|
|
18 subject, title = title.split(':', 1)
|
|
19 subject = subject[len(self.on):].lower()
|
|
20 full_subject = self.on + subject + ':'
|
|
21
|
|
22 # XXX single-word subjects, for now
|
|
23
|
|
24 filename = subject + '.txt'
|
|
25 filename = os.path.join(self.directory, filename)
|
|
26
|
|
27 exists = os.path.exists(filename)
|
|
28
|
|
29 f = file(filename, 'a')
|
|
30 if exists:
|
|
31 print >> f, self.separator
|
|
32
|
|
33 body = blog_entry.body.split(full_subject, 1)[-1].strip()
|
|
34
|
|
35 print >> f, body
|
|
36 f.close()
|