Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as Python by Jay ( 5 years ago )
## System File
import os
import sys
import datetime
import calendar
import argparse
class Daily_EReport:
def __init__(self):
self.m_today = datetime.date.today()
self.m_yesterday = self.m_today - datetime.timedelta(days = 1)
# self.m_thedaybeforeyesterday = self.m_yesterday - datetime.timedelta(days = 1)
self.m_today_day = self.m_today.strftime("%d")
self.m_thismonth = int(self.m_today.strftime("%m"))
self.m_thismonth_name = self.m_today.strftime("%B")
self.m_thisyear = int(self.m_today.strftime("%y"))
_, self.num_days = calendar.monthrange(self.m_thisyear, self.m_thismonth)
self.m_thismonth = str(self.m_thismonth).zfill(2)
self.m_certainday = None
self.m_thedaybeforecertainday = None
self.timerange = None
self.filenamepostfix = None
def yesterday(self):
# self.timerange = '{}/00/00/00 {}/00/00/00'.format(self.m_thedaybeforeyesterday.strftime("%m/%d/%y"), self.m_yesterday.strftime("%m/%d/%y"))
self.timerange = '{0}/00/00/00 {0}/23/59/00'.format(self.m_yesterday.strftime("%m/%d/%y"))
self.filenamepostfix = self.m_yesterday.strftime("%Y%m%d")
def today(self):
self.timerange = '{0}/00/00/00 {0}/23/59/00'.format(self.m_today.strftime("%m/%d/%y"))
self.filenamepostfix = self.m_today.strftime("%Y%m%d")
def thismonth(self):
self.timerange = '{0}/01/{1}/00/00/00 {0}/{2}/{1}/00/00/00'.format(self.m_thismonth, self.m_thisyear, self.m_today_day)
self.filenamepostfix = "???"
def certainday(self, day):
day = int(day)
if day < 1 or day > self.num_days:
print("There is no {0} in {1}".format(day, self.m_thismonth_name))
else:
self.m_certainday = datetime.datetime.strptime('{0} {1} {2}'.format(self.m_thismonth, day, self.m_thisyear), '%m %d %y')
self.m_thedaybeforecertainday = self.m_certainday - datetime.timedelta(days = 1)
self.timerange = '{0}/00/00/00 {1}/00/00/00'.format(self.m_thedaybeforecertainday.strftime("%m/%d/%y"), self.m_certainday.strftime("%m/%d/%y"))
self.filenamepostfix = self.m_certainday("%Y%m%d")
def report(self):
if self.timerange:
print("$ACSDIR/bin/SEReport -t A -a A -c A {0} 269 ./TEMPFILE.txt".format(self.timerange))
os.system("$ACSDIR/bin/SEReport -t A -a A -c A {} 269 ./TEMPFILE.txt".format(self.timerange))
f = open("TEMPFILE.txt", "r")
f_new = open("Daily_Event_Report-{0}.txt".format(self.filenamepostfix), "w")
f_soe = open("Daily_Event_Report-{0}-SOE.txt".format(self.filenamepostfix), "w")
lines = f.readlines()
for line in lines:
line = line.split()
if len(line) > 0:
if '/' in line[0]:
f_new.write(' '.join(line) + '\n')
if line[1].count(':') == 3:
f_soe.write(' '.join(line) + '\n')
f_new.close()
f.close()
os.remove("TEMPFILE.txt")
def get_parser():
""" The argument parser of the command-line version """
parser = argparse.ArgumentParser(description='Run_Daily_EReport')
group = parser.add_mutually_exclusive_group()
group.add_argument("-c", "--choice", help="Run_Daily_EReport.py -c ALL, \n Run_Daily_EReport.py default is yesterday", choices=[ 'today', 'ALL'])
group.add_argument("-d", "--day", help="Run_Daily_EReport.py -d 1 ")
#group.add_argument("-h", "--help", help="Support format ")
return parser
def main():
parser = get_parser()
args = parser.parse_args()
DE = Daily_EReport()
if not args.choice:
DE.yesterday()
if args.choice:
if args.choice == 'yesterday':
DE.yesterday()
elif args.choice == 'today':
DE.today()
elif args.choice == 'ALL':
DE.thismonth()
else:
print("pass")
if args.day:
DE.certainday(args.day)
DE.report()
if __name__ == "__main__":
main()
Revise this Paste
Children: 117027