|
@@ -18,6 +18,7 @@ creds = ServiceAccountCredentials.from_json_keyfile_name('choozmointernal-2e314f
|
|
client = gspread.authorize(creds)
|
|
client = gspread.authorize(creds)
|
|
message = "提醒近期預定執行的作業如下:\n\n"
|
|
message = "提醒近期預定執行的作業如下:\n\n"
|
|
message2 = "提醒近期需完成的作業如下:\n\n"
|
|
message2 = "提醒近期需完成的作業如下:\n\n"
|
|
|
|
+message3 = "提醒以下已取消的作業需填寫取消原因:\n\n"
|
|
|
|
|
|
def notify_group(msg):
|
|
def notify_group(msg):
|
|
gid='WekCRfnAirSiSxALiD6gcm0B56EejsoK89zFbIaiZQD'
|
|
gid='WekCRfnAirSiSxALiD6gcm0B56EejsoK89zFbIaiZQD'
|
|
@@ -26,36 +27,44 @@ def notify_group(msg):
|
|
|
|
|
|
def send_line(messages):
|
|
def send_line(messages):
|
|
for message in messages:
|
|
for message in messages:
|
|
- msg = [message[i:i+1000] for i in range(0, len(message), 1000)]
|
|
|
|
- for m in msg:
|
|
|
|
- notify_group(m)
|
|
|
|
- print(m)
|
|
|
|
-
|
|
|
|
-def send_email(emails, content, has_overdue):
|
|
|
|
|
|
+ print(len(message))
|
|
|
|
+ if(len(message)>55):
|
|
|
|
+ msg = [message[i:i+1000] for i in range(0, len(message), 1000)]
|
|
|
|
+ for m in msg:
|
|
|
|
+ notify_group(m)
|
|
|
|
+ #print(m)
|
|
|
|
+
|
|
|
|
+def send_email(emails, unstarted, incomplete, canceled, has_unstarted, has_incomplete, has_canceled):
|
|
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
|
|
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
|
|
server.ehlo()
|
|
server.ehlo()
|
|
server.login(gmail_username, gmail_password)
|
|
server.login(gmail_username, gmail_password)
|
|
|
|
|
|
- for name in content:
|
|
|
|
|
|
+ for name in emails:
|
|
msg = EmailMessage()
|
|
msg = EmailMessage()
|
|
msg['Subject'] = '執行表單過期作業通知' + str(datetime.date.today())
|
|
msg['Subject'] = '執行表單過期作業通知' + str(datetime.date.today())
|
|
msg['From'] = "service@choozmo.com"
|
|
msg['From'] = "service@choozmo.com"
|
|
msg['To'] = emails[name]
|
|
msg['To'] = emails[name]
|
|
|
|
|
|
- if has_overdue[name] == 1:
|
|
|
|
- msg.set_content(content[name])
|
|
|
|
|
|
+ message = name + "您好,\n\n以下通知您目前作業現況,更新執行表單請至 https://cmm.ai/pm ,謝謝您。\n\n"
|
|
|
|
+
|
|
|
|
+ if has_unstarted[name] == 0 and has_overdue[name] == 0:
|
|
|
|
+ message += "您目前沒有過期的作業。\n\n"
|
|
else:
|
|
else:
|
|
- msg.set_content(name + "您好,\n\n您目前沒有過期的作業。\n更新執行表單請至 https://cmm.ai/pm ,謝謝您。\n\n")
|
|
|
|
|
|
+ if has_unstarted[name] == 1:
|
|
|
|
+ message += unstarted[name]
|
|
|
|
+ if has_incomplete[name] == 1:
|
|
|
|
+ message += incomplete[name]
|
|
|
|
|
|
|
|
+ if has_canceled[name] == 1:
|
|
|
|
+ message += canceled[name]
|
|
|
|
+
|
|
|
|
+ msg.set_content(message)
|
|
print ('Sending email to ' + msg['To'])
|
|
print ('Sending email to ' + msg['To'])
|
|
server.send_message(msg)
|
|
server.send_message(msg)
|
|
print ('Email sent to ' + msg['To'])
|
|
print ('Email sent to ' + msg['To'])
|
|
fname = name+'.txt'
|
|
fname = name+'.txt'
|
|
with open(fname, 'w', encoding="UTF+8") as f:
|
|
with open(fname, 'w', encoding="UTF+8") as f:
|
|
- if has_overdue[name] == 1:
|
|
|
|
- f.write(content[name])
|
|
|
|
- else:
|
|
|
|
- f.write(name + "您好,\n\n您目前沒有過期的作業。\n更新執行表單請至 https://cmm.ai/pm ,謝謝您。\n\n")
|
|
|
|
|
|
+ f.write(message)
|
|
|
|
|
|
server.close()
|
|
server.close()
|
|
|
|
|
|
@@ -65,81 +74,126 @@ sheet_instance = sheet.get_worksheet(0)
|
|
records_data = sheet_instance.get_all_records()
|
|
records_data = sheet_instance.get_all_records()
|
|
#print(records_data[0])
|
|
#print(records_data[0])
|
|
|
|
|
|
-emails = {"Jared": "jared@choozmo.com", "Morrison": "morrison@choozmo.com", "Ginia": "ginia@choozmo.com", "Doris": "doris@choozmo.com", "Nina": "nina.huang@choozmo.com", "Yukyo": "yukyo@choozmo.com", "Andy": "andy@choozmo.com", "Oak": "oak@choozmo.com", "Zooey": "zooey@choozmo.com", "Syuanyuri": "syuanyuri@choozmo.com", "Wizer": "wizer@choozmo.com", "Jason": "jason@choozmo.com", "Tomoya": "tomoya@choozmo.com", "詠心": "noodlesloves@gmail.com", "献竤": "fxp87257@gmail.com"}
|
|
|
|
-overdue_email_content = {}
|
|
|
|
|
|
+emails = {"Jared": "jared@choozmo.com", "Morrison": "morrison@choozmo.com", "Doris": "doris@choozmo.com", "Nina": "nina.huang@choozmo.com", "Yukyo": "yukyo@choozmo.com", "Andy": "andy@choozmo.com", "Oak": "oak@choozmo.com", "Zooey": "zooey@choozmo.com", "Yuri": "syuanyuri@choozmo.com", "Wizer": "wizer@choozmo.com", "Jason": "jason@choozmo.com", "Tomoya": "tomoya@choozmo.com", "詠心": "noodlesloves@gmail.com", "献竤": "fxp87257@gmail.com"}
|
|
|
|
+
|
|
|
|
+overdue_notstarted_content = {}
|
|
|
|
+overdue_incomplete_content = {}
|
|
|
|
+canceled_content = {}
|
|
|
|
+has_unstarted = {}
|
|
has_overdue = {}
|
|
has_overdue = {}
|
|
|
|
+has_canceled = {}
|
|
|
|
+status = [0,0,0]
|
|
|
|
|
|
for e in emails.keys():
|
|
for e in emails.keys():
|
|
- overdue_email_content[e] = e + "您好,\n\n提醒您有已過期的作業,請儘快完成以下作業。\n更新執行表單請至 https://cmm.ai/pm ,謝謝您。\n\n過期作業如下:\n\n"
|
|
|
|
|
|
+ overdue_notstarted_content[e] = "您有已過期而尚未執行的作業,請儘快執行並完成這些作業:\n\n"
|
|
|
|
+ overdue_incomplete_content[e] = "您有已過期而未完成的作業,請儘快完成這些作業:\n\n"
|
|
|
|
+ canceled_content[e] = "此外,以下已取消執行的作業請在備註欄位填寫取消原因:\n\n"
|
|
|
|
+ has_unstarted[e] = 0
|
|
has_overdue[e] = 0
|
|
has_overdue[e] = 0
|
|
|
|
+ has_canceled[e] = 0
|
|
|
|
|
|
for data in records_data:
|
|
for data in records_data:
|
|
try:
|
|
try:
|
|
- print(parser.parse(data["起始日"]), parser.parse(data["完成日"]))
|
|
|
|
- deltastart = (parser.parse(data["起始日"]).date()-datetime.date.today()).days
|
|
|
|
- deltaend = (parser.parse(data["完成日"]).date()-datetime.date.today()).days
|
|
|
|
- print(deltastart, deltaend)
|
|
|
|
- info = ""
|
|
|
|
-
|
|
|
|
- if(deltastart <= 7 and data["完成度"] == "預定執行"):
|
|
|
|
- info += "專案:" + data["專案"] + " / " + data["專案項目"] + "\n"
|
|
|
|
- info += "作業:" + data["執行項目"] + "\n"
|
|
|
|
- info += "執行人員:" + data["指派對象"] + "\n"
|
|
|
|
- info += "PM:" + data["PM"] + "\n"
|
|
|
|
- info += "預定執行期間:" + data["起始日"] + "-" + data["完成日"]
|
|
|
|
- if(deltastart>0):
|
|
|
|
- info += " (尚有"+ str(deltastart) + "天)\n\n"
|
|
|
|
- elif(deltastart==0):
|
|
|
|
- info += " (當天開始執行)\n\n"
|
|
|
|
- else:
|
|
|
|
- info += " (過期"+ str(deltastart).replace('-','') + "天)\n\n"
|
|
|
|
- overdue_email_content[data["PM"]] += info
|
|
|
|
- has_overdue[data["PM"]] = 1
|
|
|
|
- if [data["PM"]]!=[data["指派對象"]]: #sometimes you have to do the task and you are the PM
|
|
|
|
- overdue_email_content[data["指派對象"]] += info
|
|
|
|
- has_overdue[data["指派對象"]] = 1
|
|
|
|
- if data["PM"] != "Jared": #sometimes Jared is the PM
|
|
|
|
- overdue_email_content["Jared"] += info
|
|
|
|
- has_overdue["Jared"] = 1
|
|
|
|
- message += info
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- elif(deltaend <= 7 and data["完成度"] == "執行中"):
|
|
|
|
|
|
+ if(data["完成度"] == "取消"):
|
|
|
|
+ status[2] = 1
|
|
info += "專案:" + data["專案"] + " / " + data["專案項目"] + "\n"
|
|
info += "專案:" + data["專案"] + " / " + data["專案項目"] + "\n"
|
|
info += "作業:" + data["執行項目"] + "\n"
|
|
info += "作業:" + data["執行項目"] + "\n"
|
|
info += "執行人員:" + data["指派對象"] + "\n"
|
|
info += "執行人員:" + data["指派對象"] + "\n"
|
|
- info += "PM:" + data["PM"] + "\n"
|
|
|
|
- info += "完成日:" + data["完成日"]
|
|
|
|
- if(deltaend>0):
|
|
|
|
- info += " (尚有"+ str(deltaend) + "天)\n\n"
|
|
|
|
- elif(deltaend==0):
|
|
|
|
- info += " (當天完成)\n\n"
|
|
|
|
- else:
|
|
|
|
- info += " (過期"+ str(deltaend).replace('-','') + "天)\n\n"
|
|
|
|
- overdue_email_content[data["PM"]] += info
|
|
|
|
- has_overdue[data["PM"]] = 1
|
|
|
|
- if [data["PM"]]!=[data["指派對象"]]: #sometimes you have to do the task and you are the PM
|
|
|
|
- overdue_email_content[data["指派對象"]] += info
|
|
|
|
- has_overdue[data["指派對象"]] = 1
|
|
|
|
- if data["PM"] != "Jared": #sometimes Jared is the PM
|
|
|
|
- overdue_email_content["Jared"] += info
|
|
|
|
- has_overdue["Jared"] = 1
|
|
|
|
- message2 += info
|
|
|
|
|
|
+ info += "PM:" + data["PM"] + "\n\n"
|
|
|
|
+ canceled_content[data["PM"]] += info
|
|
|
|
+ has_canceled[data["PM"]] = 1
|
|
|
|
+ if [data["PM"]]!=[data["指派對象"]]: #sometimes you have to do the task and you are the PM
|
|
|
|
+ canceled_content[data["指派對象"]] += info
|
|
|
|
+ has_canceled[data["指派對象"]] = 1
|
|
|
|
+ if data["PM"] != "Jared": #sometimes Jared is the PM
|
|
|
|
+ canceled_content["Jared"] += info
|
|
|
|
+ has_canceled["Jared"] = 1
|
|
|
|
+ message3 += info
|
|
|
|
+ else:
|
|
|
|
+ print(parser.parse(data["起始日"]), parser.parse(data["完成日"]))
|
|
|
|
+ deltastart = (parser.parse(data["起始日"]).date()-datetime.date.today()).days
|
|
|
|
+ deltaend = (parser.parse(data["完成日"]).date()-datetime.date.today()).days
|
|
|
|
+ print(deltastart, deltaend)
|
|
|
|
+ info = ""
|
|
|
|
+
|
|
|
|
+ print("Project: " + data["專案"] + "Note: " + data["備註"])
|
|
|
|
+
|
|
|
|
+ if(deltastart <= 7 and data["完成度"] == "預定執行"):
|
|
|
|
+ status[0] = 1
|
|
|
|
+ info += "專案:" + data["專案"] + " / " + data["專案項目"] + "\n"
|
|
|
|
+ info += "作業:" + data["執行項目"] + "\n"
|
|
|
|
+ info += "執行人員:" + data["指派對象"] + "\n"
|
|
|
|
+ info += "PM:" + data["PM"] + "\n"
|
|
|
|
+ info += "預定執行期間:" + data["起始日"] + "-" + data["完成日"]
|
|
|
|
+ if(deltastart>0):
|
|
|
|
+ info += " (尚有"+ str(deltastart) + "天)\n\n"
|
|
|
|
+ elif(deltastart==0):
|
|
|
|
+ info += " (當天開始執行)\n\n"
|
|
|
|
+ else:
|
|
|
|
+ info += " (過期"+ str(deltastart).replace('-','') + "天)\n\n"
|
|
|
|
+ overdue_notstarted_content[data["PM"]] += info
|
|
|
|
+ has_unstarted[data["PM"]] = 1
|
|
|
|
+ if [data["PM"]]!=[data["指派對象"]]: #sometimes you have to do the task and you are the PM
|
|
|
|
+ overdue_notstarted_content[data["指派對象"]] += info
|
|
|
|
+ has_unstarted[data["指派對象"]] = 1
|
|
|
|
+ if data["PM"] != "Jared": #sometimes Jared is the PM
|
|
|
|
+ overdue_notstarted_content["Jared"] += info
|
|
|
|
+ has_unstarted["Jared"] = 1
|
|
|
|
+ message += info
|
|
|
|
+ elif(deltaend <= 7 and data["完成度"] == "執行中"):
|
|
|
|
+ status[1] = 1
|
|
|
|
+ info += "專案:" + data["專案"] + " / " + data["專案項目"] + "\n"
|
|
|
|
+ info += "作業:" + data["執行項目"] + "\n"
|
|
|
|
+ info += "執行人員:" + data["指派對象"] + "\n"
|
|
|
|
+ info += "PM:" + data["PM"] + "\n"
|
|
|
|
+ info += "完成日:" + data["完成日"]
|
|
|
|
+ if(deltaend>0):
|
|
|
|
+ info += " (尚有"+ str(deltaend) + "天)\n\n"
|
|
|
|
+ elif(deltaend==0):
|
|
|
|
+ info += " (當天完成)\n\n"
|
|
|
|
+ else:
|
|
|
|
+ info += " (過期"+ str(deltaend).replace('-','') + "天)\n\n"
|
|
|
|
+ overdue_incomplete_content[data["PM"]] += info
|
|
|
|
+ has_overdue[data["PM"]] = 1
|
|
|
|
+ if [data["PM"]]!=[data["指派對象"]]: #sometimes you have to do the task and you are the PM
|
|
|
|
+ overdue_incomplete_content[data["指派對象"]] += info
|
|
|
|
+ has_overdue[data["指派對象"]] = 1
|
|
|
|
+ if data["PM"] != "Jared": #sometimes Jared is the PM
|
|
|
|
+ overdue_incomplete_content["Jared"] += info
|
|
|
|
+ has_overdue["Jared"] = 1
|
|
|
|
+ message2 += info
|
|
|
|
|
|
except:
|
|
except:
|
|
print("PASS")
|
|
print("PASS")
|
|
|
|
|
|
message += "更新執行表單請至 https://cmm.ai/pm"
|
|
message += "更新執行表單請至 https://cmm.ai/pm"
|
|
message2 += "更新執行表單請至 https://cmm.ai/pm"
|
|
message2 += "更新執行表單請至 https://cmm.ai/pm"
|
|
|
|
+message3 += "更新執行表單請至 https://cmm.ai/pm"
|
|
|
|
|
|
messages = []
|
|
messages = []
|
|
messages.append(message)
|
|
messages.append(message)
|
|
messages.append(message2)
|
|
messages.append(message2)
|
|
|
|
+messages.append(message3)
|
|
|
|
|
|
|
|
+print(has_unstarted)
|
|
print(has_overdue)
|
|
print(has_overdue)
|
|
|
|
+print(has_canceled)
|
|
|
|
+print(status)
|
|
|
|
+
|
|
|
|
+fname="msg1.txt"
|
|
|
|
+with open(fname, 'w', encoding="UTF+8") as f:
|
|
|
|
+ f.write(message)
|
|
|
|
+
|
|
|
|
+fname="msg2.txt"
|
|
|
|
+with open(fname, 'w', encoding="UTF+8") as f:
|
|
|
|
+ f.write(message2)
|
|
|
|
+
|
|
|
|
+fname="msg3.txt"
|
|
|
|
+with open(fname, 'w', encoding="UTF+8") as f:
|
|
|
|
+ f.write(message3)
|
|
|
|
|
|
send_line(messages)
|
|
send_line(messages)
|
|
-send_email(emails, overdue_email_content, has_overdue)
|
|
|
|
|
|
+send_email(emails, overdue_notstarted_content, overdue_incomplete_content, canceled_content, has_unstarted, has_overdue, has_canceled)
|
|
|
|
|
|
'''notify_group(message)
|
|
'''notify_group(message)
|
|
time.sleep(5)
|
|
time.sleep(5)
|