From f473565b37b4dd52528396d8a0fc91263e1fa427 Mon Sep 17 00:00:00 2001 From: Stefan Ritter Date: Sat, 21 Jan 2012 00:42:23 +0100 Subject: Add commandline parser --- blogthon.cgi | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/blogthon.cgi b/blogthon.cgi index 6d3993f..99265c8 100755 --- a/blogthon.cgi +++ b/blogthon.cgi @@ -24,6 +24,7 @@ from hashlib import md5 from glob import glob from random import randint from codecs import getwriter +from optparse import OptionParser # print() will output ascii, but we want utf-8 (python3) try: @@ -192,6 +193,36 @@ else: else: locale.setlocale(locale.LC_TIME, None) +# Commandline arguments +parser = OptionParser() +parser.add_option("-i", "--info", help="show statistics about your blog", action="store_true", dest="info") +parser.add_option("-t", "--tags", help="read all tags and create new index", action="store_true", dest="tags") +options, args = parser.parse_args() + +if vars(options).values().count(True) > 1: + print("Too much arguments, just take one!") + sys.exit(0) + +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") + for line in content: + 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...") + sys.exit(0) + # Read POST variables action = FieldStorage() month_display = action.getvalue("m") -- cgit v1.2.3