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)]
22 for (year, month, day), posts in blog_dict.items():
23 _new_dict[year, month, day] = _posts = []
24 for _file, _title, _lead, _tags in posts:
25 tags_lower = [tag.lower() for tag in _tags]
26 _posts.append((_file, _title, _lead, _tags, tags_lower))
32 for posts in blog_dict.values():
33 for _file, _title, _lead, _tags, _tags_lower in posts:
35 ix = _tags_lower.index(ltag)
42 def _test_post(post, tree):
43 """Test if the list of tags in the post satisfies condition
45 Recursively evaluate the tree against the list of tags in the post.
51 assert isinstance(tag, str)
52 return tag.lower() in post[4]
53 elif op in ('AND', 'OR'):
54 value1 = _test_post(post, tree[1])
55 value2 = _test_post(post, tree[2])
57 return value1 and value2
59 return value1 or value2
61 return not _test_post(post, tree[1])
63 return _test_post(post, tree[1])
65 raise ValueError("Cannot get there")
69 """Test every blog post against parsed expression
71 Return all posts that passed the test.
75 for (year, month, day), posts in blog_dict.items():
77 if _test_post(post, tree):
81 (year, month, day, post[0][:-len("tmpl")] + "html")),
83 _posts.sort(reverse=True)