]> git.phdru.name Git - phdru.name/cgi-bin/blog-ru/search-tags.git/blobdiff - tags.py
Process single tag
[phdru.name/cgi-bin/blog-ru/search-tags.git] / tags.py
diff --git a/tags.py b/tags.py
new file mode 100644 (file)
index 0000000..7ff886d
--- /dev/null
+++ b/tags.py
@@ -0,0 +1,25 @@
+blog_filename = "blog_dict.pickle"
+
+try:
+   import cPickle as pickle
+except ImportError:
+   import pickle
+
+try:
+   blog_file = open(blog_filename, "rb")
+except IOError:
+   blog_dict = {}
+else:
+   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 _file, _title, _lead, tags in posts:
+            if tag in tags:
+                return True
+    return False