-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSetNoti.py
70 lines (61 loc) · 2.29 KB
/
SetNoti.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
import os
# from posixpath import split
import sys
from BOOT import listMails
from Mails.SendPDF import *
from Mails.BootMails import *
def FunList(List):
"""[Takes list and prints it vertically assigning each item its index number on CLI]
Args:
List ([string]): [The items to be displayed]
Returns:
[string]: [a string displaying entries vertically with its indexes]
"""
rtnList = "\n"
for i in range(len(List)):
rtnList += f"{i+1} - {List[i]}\n"
return rtnList
def GetPath(path = os.path.join(sys.path[0], "LOCAL")):
"""[Walk through directories and return the list of sub-directories]
Args:
path ([string], optional): [path of directory to start walking through]. Defaults to the path of storage.
Returns:
[string]: [path of internally selected directory unless it finds credentials file or the zero is entered as input.]
"""
try:
dirs = os.listdir(path)
if "CREs.txt" in dirs or len(dirs)==0:
return path
print(FunList(dirs))
c = int(input("Enter the Dir num: "))
if c == 0:
return path
return GetPath(os.path.join(path, dirs[c-1]))
except Exception as e:
print(e)
return path
def AskNoti():
"""[To replace the notification from one folder to the storage and send the email to the respective members.]
"""
C_Noti = input("Enter the path of the notification: ")
if not os.path.exists(C_Noti):
print("Path doesnot exists...")
return
T_Path = os.path.join(GetPath(), os.path.split(C_Noti)[1])
if not "Student" in T_Path:
sendPDFMail("A new notification has been added.", C_Noti, subject="A new notification", recievers=listMails)
else:
with open(os.path.join(T_Path, "CREs.txt"), "r") as f:
R = DC(f.read()).split("\n")[2].split(": ")[1].strip()
sendPDFMail("A new notification has been added.", C_Noti, subject="A new notification", recievers=[R])
os.replace(C_Noti, T_Path)
# ! sendMailNoti(T_path)
def AdminLog():
Pass = PasswordGenerator()
SendBootCre(Pass, Topic="admin")
if input("Enter the password sent you through mail: ") == Pass:
AskNoti()
else:
print("Wrong Credentials...")
if __name__ == '__main__':
AskNoti()