ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/MW/SMS_Re-reminder.py
Revision: 8
Committed: Sat May 5 04:21:19 2012 UTC (13 years, 10 months ago) by ninoborges
Content type: text/x-python
Original Path: Python/NinoCode/MW/SMS_Re-reminder.py
File size: 5611 byte(s)
Log Message:
Initial Import

File Contents

# User Rev Content
1 ninoborges 8 ## SMS_Re-reminder.py
2     ## This application will augument SMS's advertisement process by re-reminding the user that they have new advertisements
3     ## to run.
4     ## 02.07.03
5     ## EBorges
6    
7     import os,time
8     from _winreg import *
9     from getpass import getuser
10    
11    
12    
13     ## Function: checkForPackage
14     ## Purpose: This function will check for new Advertisements in the "newJobsDir" directory. If new advertisements
15     ## are found it will check to see if the reminder has run today. If it has not and it is not the first
16     ## day of the advertisement(That will let SMS remind them first), it will call the runReminder function
17     ## that will force the remind to happen
18     ## Arguments: newJobsDir - The directory that the re-reminder will look for the existince of new advertisements.
19     ## offerFilesDir - The directory that will be reset if a remind routine needs to be run.
20     ## logFile - A complete log file object. Path and file name.
21     def checkForPackage(newJobsDir,offerFilesDir,userName,logFile):
22     files = os.listdir(newJobsDir)
23     todayDate = time.strftime('%m/%d/%Y')
24     try:
25     # First check to see if it exists.
26     rKeyObj = OpenKey( HKEY_LOCAL_MACHINE, 'Software\\McGuireWoods LLP\\SMS\\Remind')
27     lastRunDate = QueryValueEx(rKeyObj,'DateLastRun')[0]
28     bothFilesExisted = QueryValueEx(rKeyObj,'BothFilesExist')[0]
29     rKeyObj.Close()
30     wKeyObj = OpenKey( HKEY_LOCAL_MACHINE, 'Software\\McGuireWoods LLP\\SMS\\Remind',0,KEY_WRITE)
31     except WindowsError:
32     # If it does not, this must be the first time it is run. Create structure.
33     wKeyObj = CreateKey( HKEY_LOCAL_MACHINE, 'Software\\McGuireWoods LLP\\SMS\\Remind')
34     files = ""
35     if files:
36     if checkLastRun(logFile,wKeyObj,todayDate,lastRunDate,bothFilesExisted):
37     # "I have jobs to run and I have not yet run today. Running the reminder..."
38     runReminder(offerFilesDir,userName)
39     else:
40     # Files didnt exist. Exit with setting the date to today and the dword to 0
41     SetValueEx(wKeyObj,'DateLastRun','',1,todayDate)
42     SetValueEx(wKeyObj,'BothFilesExist','',4,0)
43     wKeyObj.Close()
44    
45     ## Function: runReminder
46     ## Purpose: This function will delete the OFR files in the MWBB.DOM directory thereby forcing SMS ro re-remind
47     ## the user that there are advertisements to run.
48     ## Arguments: offerFilesDir - The directory that will be reset if a remind routine needs to be run.
49     ## userName - This will be the name of the dirctory that will need to be deleted
50     def runReminder(offerFilesDir,userName):
51     try:
52     os.system("""echo /.,zxc';lasdkf| su wsburrou "cmd /c del /Q %s\%s"""%(offerFilesDir,userName))
53     except:
54     addToLogFile(logFile,"error!! I couldent delete the files.")
55    
56     ## Function: checkLastRun
57     ## Purpose: This function will determin if a Remind should be run based on when the last date the remind
58     ## was run and if the advertisement is new.
59     ## Arguments logFile - A complete log file object. Path and file name. This is the file the program will log to.
60     ## iKeyObj - A complete registry open object.
61     ## todayDate - Todays date.
62     ## lastRunDate - The last date this program was run.
63     ## bothFilesExisted - Int 0 or 1 to state if the files exist
64     def checkLastRun(logFile,wKeyObj,todayDate,lastRunDate,bothFilesExisted):
65     if lastRunDate != todayDate:
66     # "I have not yet run today"
67     if bothFilesExisted:
68     # "check last run has found that the d word was 1 so that means I should run."
69     addToLogFile(logFile,'A new advertisement is avalible and still has not run. Reminding user...')
70     # Reset the date to today and the dword to 0
71     SetValueEx(wKeyObj,'BothFilesExist','',4,0)
72     SetValueEx(wKeyObj,'DateLastRun','',1,todayDate)
73     remind = "yes"
74     else:
75     # "there are packages to run but the dword was 0 so sms must have reminded today. seting dword to 1"
76     SetValueEx(wKeyObj,'BothFilesExist','',4,1)
77     SetValueEx(wKeyObj,'DateLastRun','',1,todayDate)
78     remind = ""
79     else:
80     # "there are packages to run but I have already run today. Not writing to log"
81     #addToLogFile(logFile,'A new advertisement is avalible and still has not run but I have already run today.')
82     SetValueEx(wKeyObj,'BothFilesExist','',4,1)
83     remind = ""
84     return remind
85    
86    
87     ## Function: addToLogFile
88     ## Purpose: This function will add one entry to the log file pased to it.
89     ## Arguments: logFile - The path and file that this function will write to.
90     ## logEntry - The entry that will be inserted into the logfile.
91     ## echo - Whether python should print the entry to stdout.
92     def addToLogFile(logFile, logEntry, echo=0 ):
93     try:
94     log_file = open( logFile, 'a' )
95     except IOError:
96     log_file = open( logFileName, 'a' )
97     log_file.write( time.strftime('%m/%d/%Y\t%H:%M:%S -\t',time.localtime()) + logEntry + '\n' )
98     if echo == 1: print logEntry
99     log_file.close()
100    
101    
102     if __name__ == '__main__':
103     winDir = os.environ['SMS_LOCAL_DIR']
104     userName = os.environ['USERNAME']
105     newJobsDir = winDir + r"\ms\sms\clicomp\apa\Data\Jobs"
106     #completeFilesDir = winDir + r"\ms\sms\clicomp\apa\Data\Complete"
107     offerFilesDir = winDir + r"\ms\sms\clicomp\apa\Data\New\MWBB.DOM"
108     logFile = winDir + r'\ms\sms\LOGS\SMS_Re-reminder.log'
109     checkForPackage(newJobsDir,offerFilesDir,userName,logFile)