]> git.phdru.name Git - phdru.name/cgi-bin/blog-ru/search-tags.git/blobdiff - tags.py
Python 3
[phdru.name/cgi-bin/blog-ru/search-tags.git] / tags.py
diff --git a/tags.py b/tags.py
index 44f1a070d02b08c02e9b1f265ba9ec8095bd5fb5..3fe860bdfab7fcfaa196726a11fc9bcae95ca7b0 100644 (file)
--- a/tags.py
+++ b/tags.py
@@ -1,29 +1,30 @@
 blog_filename = "blog_dict.pickle"
 
 try:
-   import cPickle as pickle
+    import cPickle as pickle
 except ImportError:
-   import pickle
+    import pickle
 
 try:
-   blog_file = open('../../../../phdru.name/ru/' + blog_filename, "rb")
+    blog_file = open('../../../../phdru.name/ru/' + blog_filename, "rb")
 except IOError:
-   blog_dict = {}
+    blog_dict = {}
 else:
-   blog_dict = pickle.load(blog_file)
-   blog_file.close()
+    blog_dict = pickle.load(blog_file)
+    blog_file.close()
 
 
 # blog_dict is a mapping
 # (year, month, day) => [list of (file, title, lead, tags)]
 
 def tag_exists(tag):
-    for posts in blog_dict.itervalues():
+    for posts in blog_dict.values():
         for _file, _title, _lead, _tags in posts:
             if tag in _tags:
                 return True
     return False
 
+
 def _test_post(post, tree):
     """Test if the list of tags in the post satisfies condition
 
@@ -50,6 +51,7 @@ def _test_post(post, tree):
     else:
         raise ValueError("Cannot get there")
 
+
 def find_tags(tree):
     """Test every blog post against parsed expression
 
@@ -57,12 +59,13 @@ def find_tags(tree):
 
     """
     _posts = []
-    for (year, month, day), posts in blog_dict.iteritems():
+    for (year, month, day), posts in blog_dict.items():
         for post in posts:
             if _test_post(post, tree):
                 _posts.append((
                     year, month, day,
-                    '/'.join((year, month, day, post[0][:-len("tmpl")] + "html")),
+                    '/'.join(
+                        (year, month, day, post[0][:-len("tmpl")] + "html")),
                     post[1]))
     _posts.sort(reverse=True)
     return _posts