-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelperFunctions.py
72 lines (58 loc) · 2.09 KB
/
HelperFunctions.py
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
from dotenv import load_dotenv
from Emailer import *
import os, json
def create_step(instruction):
check_symbol = "☐"
# check_symbol = "-"
return "{} {}\n".format(check_symbol, instruction)
def get_header(name, date_maintenance):
header = "Hi {},\n\nThis is a reminder that tomorrow ({}) is your turn to do the LFL Lab Maintenance. Please refer to the following checklist.\n\n".format(name, date_maintenance)
return header
def get_signature(bot_name="LFL Bot"):
salute = "🫡 "
# salute = ""
return "\n\nThank you for your service {},\n{}".format(salute, bot_name)
def create_email_content(name, date_maintenance, instructions, bot_name="LFL Bot"):
header = get_header(name, date_maintenance)
steps = []
for instruction in instructions:
steps.append(create_step(instruction))
body = "".join(steps)
signature = get_signature(bot_name)
return header + body + signature
def extract_lab_maintainer():
load_dotenv(".env")
user_id = str(os.environ.get("USER_ID"))
user_name, user_email = get_user_info(user_id)
return user_name, user_email
def get_user_info(user_id):
f = open("lab_members.json")
data = json.load(f)
user_name, user_email = data[user_id]["name"], data[user_id]["email"]
return user_name, user_email
def get_last_user_id():
f = open("lab_members.json")
data = json.load(f)
id_num = int(list(data.keys())[-1])
return id_num
def send_email(email,subjectLine, emailContent):
sms_list = ['']
sender = Emailer(email, sms_list, subjectLine, emailContent)
sender.send_email()
def update_record(f=".env"):
# Read in the file
load_dotenv(f)
last_id = get_last_user_id()
with open(f, 'r') as file :
filedata = file.read()
# Replace the target string
user_id = int(os.environ.get("USER_ID"))
target = "ID="+str(user_id)
if user_id != last_id:
update = "ID="+str(user_id+1)
else:
update = "ID="+str(1)
filedata = filedata.replace(target, update)
# Write the file out again
with open(f, 'w') as file:
file.write(filedata)