-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimesheetMoveCreate.py
More file actions
142 lines (131 loc) · 5.02 KB
/
timesheetMoveCreate.py
File metadata and controls
142 lines (131 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import win32com.client as win32
import psutil
import os
import subprocess
import openpyxl
from pathlib import Path
from datetime import datetime, date
#import win32api
today = date.today()
now = datetime.now()
#Create and Set the year, month, and day variables
year = now.strftime("%Y")
month = now.strftime("%m")
day = now.strftime("%d")
monday = int(day) - 4 #created the variable for monday (4 days before)
mondayString = str(monday)
mondayFullDate = month + '/' + mondayString + '/' + year
weekOf = month + '_' + mondayString + '_' + year
extend = month + '_' + mondayString + '_' + year + ".xlsx"
filename = "C:\\Users\\YourDesiredNewFileName" + extend
#Opens the XLSX Workbook and assigns appropriate cell values
def fileUpdate():
print("Loading Workbook")
wb = openpyxl.load_workbook('C:\\Users\\YourPathHere') #Path to reference file for update
sheet = wb['Sheet1'] #Selects the sheet
print("Updating Date")
sheet['B9'] = mondayFullDate #Sets the date to Monday (4 days earlier) on cell B9
dayOff = input("Did you have a day off? If so, what type of day (Enter 0, S, J, BH, or V) or 'n' for none: ")
dayOff = dayOff.lower()
answers = ['0', 's', 'j', 'bh', 'v']
none = ['n', 'none']
if dayOff not in answers:
print("Please enter a valid response")
elif dayOff in none:
print("here")
#print(sheet['B9'].value)
#print(fileName)
print("Saving new file...")
wb.save(filename)
print("Save Succesful!")
sendNotification()
elif dayOff in answers:
print("in dayoff .lower")
the_day_off = input("Which day? M, T, W, Th, F: ")
if the_day_off.lower() == 'm':
sheet['C15'] = dayOff.upper()
print("Saving new file...")
wb.save(filename)
print("Save Succesful!")
sendNotification()
elif the_day_off.lower() == 't':
sheet['C16'] = dayOff.upper()
print("Saving new file...")
wb.save(filename)
print("Save Succesful!")
sendNotification()
elif the_day_off.lower() == 'w':
sheet['C17'] = dayOff.upper()
print("Saving new file...")
wb.save(filename)
print("Save Succesful!")
sendNotification()
elif the_day_off.lower() == 'th':
sheet['C18'] = dayOff.upper()
print("Saving new file...")
wb.save(filename)
print("Save Succesful!")
sendNotification()
elif the_day_off.lower() == 'f':
sheet['C19'] = dayOff.upper()
print("Saving new file...")
wb.save(filename)
print("Save Succesful!")
sendNotification()
else:
print("No days off! #Grindreel")
print("Saving new file...")
wb.save(filename)
print("Save Succesful!")
sendNotification()
# Drafting and sending email notification to senders.
# You can add other senders' email in the list
def sendNotification():
const = win32.constants
olMailItem = 0x0
obj = win32.Dispatch("Outlook.Application")
newMail = obj.CreateItem(olMailItem)
newMail.Subject = "ENTER MAIL SUBJECT HERE" + month + '/' + mondayString + '/' + year
newMail.Body = ''
newMail.BodyFormat = 2 # olFormatHTML https://msdn.microsoft.com/en-us/library/office/aa219371(v=office.11).aspx
newMail.HTMLBody = "<HTML><BODY>Hi,<br><br>Enter Your body text here <span style='font-weight: bold; text-decoration: underline'>Bold and Underline</span> More body text.<br><br>Thanks,<br>Your Name</BODY></HTML>" #"<HTML><BODY>Enter \nthe <span style='color:red'>message</span> text here.</BODY></HTML>"
newMail.To = "to@example.com"
newMail.CC = "cc@example.com"
attachment1 = filename
print("Attaching", attachment1)
newMail.Attachments.Add(Source=attachment1)
print("Attachment Added")
print("Opening message...")
newMail.display(True)
#newMail.send()
print("Mail Successfully Sent!")
quit()
# Open Outlook.exe. Path may vary according to system config
# Please check the path to .exe file and update below
'''def openOutlook():
print("Checking if Microsoft Outlook is open...")
try:
subprocess.call(['C:\Program Files\Microsoft Office\Office15\Outlook.exe'])
os.system("C:\Program Files\Microsoft Office\Office15\Outlook.exe");
except:
print("Outlook didn't open successfully")
print("Trying again...")
# Checking if outlook is already opened. If not, open Outlook.exe and send email
for item in psutil.pids():
p = psutil.Process(item)
if p.name() == "OUTLOOK.EXE":
flag = 1
break
else:
flag = 0
if (flag == 1):
fileUpdate() #was sendNotification()
else:
openOutlook()
sendNotification()
fileUpdate()'''
def main():
#openOutlook()
sendNotification()
if __name__ == "__main__":
main()