-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
136 lines (114 loc) · 4.13 KB
/
main.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
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
#delete prev file
#rename curr file as prev file
#create curr file
#compare curr and prev files
from get_from_moodle import main
from compare import compare
import os
import shutil
import getpass
import tkinter as tk
import smtplib
from email_text import sendmail
from tkinter import *
from functools import partial
from PIL import Image, ImageTk
import os
from ui import *
import sys
from datetime import datetime
import time
def exists(username,password):
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--start-maximized')
driver = webdriver.Chrome(os.getcwd()+"/chromedriver",options=chrome_options)
driver.get("https://moodle.iitd.ac.in/login/index.php")
ufield = driver.find_element_by_id("username")
ufield.send_keys(username)
pfield = driver.find_element_by_id("password")
pfield.send_keys(password)
captcha = driver.find_element_by_id("page-login-index").text.split("\n")[9].split()
cfield = driver.find_element_by_id("valuepkg3")
if "subtract" in captcha:
captcha = str(int(captcha[-4])-int(captcha[-2]))
elif "add" in captcha:
captcha = str(int(captcha[-4])+int(captcha[-2]))
elif "first" in captcha:
captcha = captcha[-4]
elif "second" in captcha:
captcha = captcha[-2]
cfield.send_keys(captcha)
cfield.send_keys(Keys.RETURN)
return (driver.current_url!="https://moodle.iitd.ac.in/login/index.php")
notifs=[]
prev=None
def login():
username = userName.get()
Pass = password.get()
em = email.get()
with open("user_info.txt","w") as file:
file.write(username+"\n"+Pass+"\n"+em)
time.sleep(5)
window = Tk()
window.geometry("800x500+300+100")
window.minsize(800, 500)
window.maxsize(800, 500)
window.title("Moodle Notifications")
window.iconbitmap(os.getcwd()+"/icon.png")
window.configure(background='orange')
label1 = Label(window, text = " Moodle Login Info ", fg = "white", bg="orange", font = ("new times roman", 40, "bold"))
label1.place(x = 230, y = 15)
label2 = Label(window, text = "Username :", fg = "black", bg="orange", font = ("arial", 16, "normal"))
label2.place(x = 190, y = 150)
userName = StringVar()
textBox1 = Entry(window, textvar = userName, width = 30, font = ("arial", 16, "bold"))
textBox1.place(x = 290, y = 150)
label3 = Label(window, text = "Password :", fg = "black", bg="orange", font = ("arial", 16, "normal"))
label3.place(x = 190, y = 200)
password = StringVar()
textBox2 = Entry(window, textvar = password, show="*", width = 30, font = ("arial", 16, "bold"))
textBox2.place(x = 290, y = 200)
label4 = Label(window, text = "E-mail ID :", fg = "black", bg="orange", font = ("arial", 16, "normal"))
label4.place(x = 200, y = 250)
email = StringVar()
textBox3 = Entry(window, textvar = email, width = 30, font = ("arial", 16, "bold"))
textBox3.place(x = 290, y = 250)
button1 = Button(window, text = " Login ", fg = "black", bg = "orange", relief = "raised", font = ("arial", 16, "bold"), command = login)
button1.place(x = 370, y = 310)
#button2 = Button(window, text="Quit", command=window.destroy)
#button2.place(x = 450, y = 310)
window.mainloop()
info = open("user_info.txt", "r")
lines = info.readlines()
if(len(lines)==0 or lines[0]=="\n"):
sys.exit()
username = lines[0][:-1]
password = lines[1][:-1]
email = lines[2]
while(not exists(username, password)):
ui()
info = open("user_info.txt", "r")
lines = info.readlines()
if(len(lines)==0 or lines[0]=="\n"):
sys.exit()
username = lines[0][:-1]
password = lines[1][:-1]
email = lines[2]
main(username, password)
while(True):
os.system("rm -r prev.txt")
os.rename("curr.txt", "prev.txt")
main(username, password)
curr = open("curr.txt", "r")
prev = open("prev.txt", "r")
compare(curr, prev, notifs)
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
if current_time.split(":")[0] in ("20","21") and now.day!=prev and not notifs:
prev=now.day
sendmail(email,notifs)
notifs=[]