Create tag index

This commit is contained in:
Stefan Ritter 2012-01-21 02:14:21 +01:00
parent 13bbcd8e68
commit b3da1c5e4e

View File

@ -18,6 +18,7 @@ import sys
import time
import locale
import re
import marshal
from cgi import FieldStorage
from smtplib import SMTP
from hashlib import md5
@ -207,7 +208,6 @@ if vars(options).values().count(True) > 1:
if options.info:
num_entries = len(glob(os.path.join(entries_dir, "*." + entries_suffix)))
num_comments = 0
comments = glob(os.path.join(entries_dir, "*.comments"))
for file in comments:
content = open(file, "r")
@ -215,13 +215,28 @@ if options.info:
if line.startswith("-"):
num_comments += 1
content.close()
print("Number of entries: %s" % num_entries)
print("Number of comments: %s" % num_comments)
sys.exit(0)
if options.tags:
print("Tags are coming soon...")
try:
tagindex = []
entries = glob(os.path.join(entries_dir, "*." + entries_suffix))
for entry in entries:
content = open(entry, "r")
tagline = content.readline().strip()
if re.match(line_start_plus, tagline):
taglist = tagline.split("+")[1:]
for tag in taglist:
tagindex.append([tag.strip(), entry])
content.close()
tagfile = open(os.path.join(entries_dir, "tags"), "w")
marshal.dump(tagindex, tagfile)
tagfile.close()
print("Index created!")
except:
print("Error creating index!")
sys.exit(0)
# Read POST variables