Add commandline parser
This commit is contained in:
parent
bdbc414fea
commit
f473565b37
31
blogthon.cgi
31
blogthon.cgi
@ -24,6 +24,7 @@ from hashlib import md5
|
|||||||
from glob import glob
|
from glob import glob
|
||||||
from random import randint
|
from random import randint
|
||||||
from codecs import getwriter
|
from codecs import getwriter
|
||||||
|
from optparse import OptionParser
|
||||||
|
|
||||||
# print() will output ascii, but we want utf-8 (python3)
|
# print() will output ascii, but we want utf-8 (python3)
|
||||||
try:
|
try:
|
||||||
@ -192,6 +193,36 @@ else:
|
|||||||
else:
|
else:
|
||||||
locale.setlocale(locale.LC_TIME, None)
|
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
|
# Read POST variables
|
||||||
action = FieldStorage()
|
action = FieldStorage()
|
||||||
month_display = action.getvalue("m")
|
month_display = action.getvalue("m")
|
||||||
|
Loading…
Reference in New Issue
Block a user