-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_present_prn.py
100 lines (60 loc) · 2.5 KB
/
test_present_prn.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
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
import pickle
import os
from datetime import datetime
import pymongo as pm
from collections import OrderedDict
from pathlib import Path
import pymongo as pm
import smtplib
final_file_prev= Path("final_presnt_prn.p")
if (final_file_prev.is_file()):
os.remove("final_presnt_prn.p")
loaded_prn_file = open("present.p", 'rb')
loaded_prn_list = pickle.load(loaded_prn_file)
loaded_prn_file.close()
non_duplicates = list(OrderedDict.fromkeys(loaded_prn_list))
final_save_file = open("final_presnt_prn.p", 'wb')
pickle.dump(non_duplicates, final_save_file)
final_save_file.close()
non_duplicates=sorted(non_duplicates)
print("welcome to pymongo")
client_0 = pm.MongoClient("mongodb://localhost:27017")
print(client_0)
Base_db= client_0["Students_DB"]
base_col = Base_db["Students_Col"]
now = datetime.now()
dt_string = now.strftime("%d_%m_%Y %H:%M:%S")
print("date and time =", dt_string)
file_name= ("Attendance_db_"+dt_string)
attendance_db= client_0["Attendance_DB"]
attendance_col = attendance_db[file_name]
for i in non_duplicates:
curr_doc_present=base_col.find_one({'_id':int(i)})
print("Present Studnets:")
print(curr_doc_present['_id'])
attendance_col.insert_one(curr_doc_present)
base_cur_= base_col.find()
present_DB_cur = attendance_col.find()
print("\n\n\n")
set_present = set(non_duplicates)
base_prn=[]
for i in base_cur_:
base_prn.append(int(i['_id']))
set_base_prn=set(base_prn)
set_absent = set(set_base_prn-set_present)
server = smtplib.SMTP("smtp.gmail.com", 587)
server.ehlo()
server.starttls()
server.login("<your email>", "<your password>")
for i in set_present:
curr_doc=base_col.find_one({'_id':int(i)})
message ='\n\n\n\nPRESENT \n\n\nAttendance status: PRESENT \nName: '+curr_doc['name']+ '\nRoll No: '+ str(curr_doc['rol_no'])
# server.sendmail("sakharevig@gmail.com", curr_doc['email'], message)
server.sendmail("sakharevig@gmail.com", "aditya2004cs@gmail.com", message)
print("mail sent as present to ",i ," ", curr_doc['email'])
for i in set_absent:
curr_doc=base_col.find_one({'_id':int(i)})
message ='\n\n\n\nABSENT \n\n\nAttendance status: ABSENT \nName: '+curr_doc['name']+ '\nRoll No: '+ str(curr_doc['rol_no'])
# server.sendmail("sakharevig@gmail.com", "aditya2004cs@gmail.com", message)
# server.sendmail("sakharevig@gmail.com", curr_doc['email'], message)
print("mail sent as absent to ",i," ", curr_doc['email'])