1 blog_filename = "blog_dict.pickle"
4 import cPickle as pickle
9 blog_file = open('../../../../phdru.name/ru/' + blog_filename, "rb")
13 blog_dict = pickle.load(blog_file)
17 # blog_dict is a mapping
18 # (year, month, day) => [list of (file, title, lead, tags)]
21 for posts in blog_dict.itervalues():
22 for _file, _title, _lead, _tags in posts:
27 def _test_post(post, tree):
28 """Test if the list of tags in the post satisfies condition
30 Recursively evaluate the tree against the list of tags in the post.
36 assert isinstance(tag, str)
39 elif op in ('AND', 'OR'):
40 value1 = _test_post(post, tree[1])
41 value2 = _test_post(post, tree[2])
43 return value1 and value2
45 return value1 or value2
47 return not _test_post(post, tree[1])
49 return _test_post(post, tree[1])
51 raise ValueError("Cannot get there")
54 """Test every blog post against parsed expression
56 Return all posts that passed the test.
60 for (year, month, day), posts in blog_dict.iteritems():
62 if _test_post(post, tree):
65 '/'.join((year, month, day, post[0][:-len("tmpl")] + "html")),
67 _posts.sort(reverse=True)