diff options
author | Stefan Ritter <xeno@thehappy.de> | 2012-01-21 00:42:23 +0100 |
---|---|---|
committer | Stefan Ritter <xeno@thehappy.de> | 2012-01-21 00:42:23 +0100 |
commit | f473565b37b4dd52528396d8a0fc91263e1fa427 (patch) | |
tree | 92683c8633562674ce7e0a07a09daafced0405c9 /blogthon.cgi | |
parent | bdbc414fea79efbec11291ef83c726233538575d (diff) |
Add commandline parser
Diffstat (limited to '')
-rwxr-xr-x | blogthon.cgi | 31 |
1 files changed, 31 insertions, 0 deletions
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") |