#!/usr/bin/python
# Version: 1.2
# Created: 2017-04-04
# Last modified: 2017-04-11
# Purpose: Count the number of requests in the various queues, e.g.,
# modified, awaiting implementation, etc.
import csv, os.path, re, sys
from datetime import datetime
section=""
sections={}
sections["Pending-Approval"] = 0
sections["Modified"] = 0
sections["Pending-Removal"] = 0
sections["On-Hold"] = 0
sections["Clarification-Required"] = 0
sections["Waiting-Implementation"] = 0
sections["Waiting-Removal"] = 0
try:
sys.argv[1]
except IndexError:
print "Error - missing input file name! Usage ./count_queued.py infile outfile"
sys.exit(1)
else:
requestfile = sys.argv[1]
try:
sys.argv[2]
except IndexError:
print "Error - missing output file name! Usage ./count_queued.py infile outfile"
sys.exit(1)
else:
countfile = sys.argv[2]
with open(requestfile, "r") as f:
# Sections are begun by a line like:
#
Requests Pending Approval:
for line in f:
if "standardbold" in line:
section = re.search('standardbold" id="(.+)">', line).group(1)
else:
if section is not "" and "a href=\"/Request/" in line:
sections[section]+=1
f.close()
print "Request Status\n"
print "Pending Approval: ", sections["Pending-Approval"]
print "Modified: ", sections["Modified"]
print "Pending Removal ", sections["Pending-Removal"]
print "On Hold: ", sections["On-Hold"]
print "Clarification Required:", sections["Clarification-Required"]
print "Waiting Implementation:", sections["Waiting-Implementation"]
print "Waiting Removal: ", sections["Waiting-Removal"]
total = sections["Pending-Approval"] + sections["Modified"] + sections["Pending-Removal"] + sections["Clarification-Required"]
print "\nTotal requiring review:", total
# Check on whether file exists and is accessible
if not os.path.isfile(countfile):
f = open(countfile, "w")
f.write("Date,Pending Approval,Modified,Pending Removal,On Hold,Clarification Required,Waiting Implementation,Waiting Removal,Total\n")
f.close()
with open(countfile,'a') as csvfile:
countfile_writer = csv.writer(csvfile, delimiter=',')
# Set the date to be the current date in YYYY-MM-DD format
theDate = str(datetime.now())[0:10]
countfile_writer.writerow([theDate, sections["Pending-Approval"], sections["Modified"], sections["Pending-Removal"], sections["On-Hold"], sections["Clarification-Required"], sections["Waiting-Implementation"], sections["Waiting-Removal"], total])
f.close()