-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
105 lines (83 loc) · 3.24 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
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
import os
from dotenv import load_dotenv , find_dotenv
import csv
import datetime
days = {"Saturday":0,"Sunday":2,"Monday":4,"Tuesday":6,"Wednesday":8}
day = datetime.datetime.now().strftime("%A")
currentTime = datetime.datetime.now().strftime("%H:%M")
load_dotenv(find_dotenv())
KALAMEKARBARI = os.getenv('KALAMEKARBARI')
RAMZ = os.getenv('RAMZ')
def dayCheck():
return day in days.keys();
while True:
if(dayCheck() == True):
break;
else:
sleep(21600)
if(os.path.exists("./hour.csv") == False):
def hourdata():
with open('hour.csv', 'w') as csvfile:
w = csv.writer(csvfile,quoting=csv.QUOTE_NONE,escapechar=' ')
save = "y"
while save == "y":
shanbe = list(map(str,input("(shanbe) saeat kelas haton ro ezafe konid (besorat => 16:00 , 13:00,...): ").split(" ")))
yekshan = list(map(str,input("(Yek shanbe) saeat kelas haton ro ezafe konid (besorat => 16:00 , 13:00,...): ").split(" ")))
doshan = list(map(str,input("(Do shanbe) saeat kelas haton ro ezafe konid (besorat => 16:00 , 13:00,...): ").split(" ")))
seshan = list(map(str,input("(Se shanbe) saeat kelas haton ro ezafe konid (besorat => 16:00 , 13:00,...): ").split(" ")))
chaharshan = list(map(str,input("(Chahar shanbe) saeat kelas haton ro ezafe konid (besorat => 16:00 , 13:00,...): ").split(" ")))
times = (shanbe,yekshan,doshan,seshan,chaharshan)
save = input("mikhaid saeat haie vared shode ro zakhire konid? Y/N: ")
if save.lower() == "y":
for row in times:
w.writerow(row)
print("---saeat haie vared shode zakhire shode---")
save = input("mikhaid dobare vared konid?? Y/N: ")
print("etmam zakhire sazi data.")
hourdata()
else:
def imprtHours():
with open("hour.csv","r") as f:
r = csv.reader(f)
times = []
hours = []
for i in r:
times.append(i)
hours.append(times[days[day]])
def attendClass():
driver = webdriver.Chrome(executable_path='./chromedriver.exe')
# Navigate to page
sleep(2)
driver.maximize_window()
sleep(2)
driver.get('https://elearning1.nit.ac.ir/')
print(driver.title)
sleep(12)
username = driver.find_element(By.ID,"username")
password = driver.find_element(By.ID,"password")
username.send_keys(KALAMEKARBARI)
password.send_keys(RAMZ)
password.send_keys(Keys.RETURN)
sleep(7)
cab = driver.find_element(By.CLASS_NAME,"fa-sign-in")
cab.click()
sleep(7)
print(driver.title)
window_after = driver.window_handles[1]
driver.switch_to.window(window_after)
sleep(20)
ActionChains(driver).send_keys(Keys.RETURN).perform()
sleep(5400)
driver.quit()
while True:
sleep(60)
if(currentTime in hours):
attendClass()
else:
continue;