-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
136 lines (114 loc) · 4.11 KB
/
utils.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
134
135
136
import configparser
import csv
import datetime
import time
from docx import Document
from pynput.keyboard import Events, Key
from pynput.keyboard import Controller as KB_Controller
from pynput.mouse import Button
from pynput.mouse import Controller as Mouse_Controller
def get_period(time):
"""Gets period based on time"""
periods = {
1: (datetime.time(7, 30), datetime.time(8, 40)),
2: (datetime.time(8, 40), datetime.time(9, 30)),
3: (datetime.time(9, 30), datetime.time(10, 25)),
4: (datetime.time(10, 25), datetime.time(11, 15)),
5: (datetime.time(11, 15), datetime.time(12, 15)),
}
for period in periods:
if periods[period][0] <= time.time() < periods[period][1]:
return period
print("No class at the moment")
input("press Enter to exit...")
raise SystemExit
def get_subject():
"""Retrieves subject based on timetable"""
with open("timetable.csv", "r") as timetable:
period = get_period(datetime.datetime.now())
timetableReader = list(csv.reader(timetable))
day = int(datetime.datetime.now().strftime("%w")) + 1
subject = timetableReader[day][period]
print("Day:", datetime.datetime.now().strftime("%A"))
print(f"Period : {period}")
print(f"subject : {subject}")
return subject
def get_credentials(subject):
"""Retrieves id and password corresponding to subject"""
subject = subject.upper()
with open("passwords.csv", "r") as passwords:
reader = csv.DictReader(passwords)
for row in reader:
if row["subject"].upper() == subject:
return row["id"], row["password"]
else:
print("Failed to obtain id and password")
raise SystemExit
def auto_type(id, password, joinposn):
"""Executes actions on Zoom.exe"""
print("id:", id)
keyboard = KB_Controller()
mouse = Mouse_Controller()
with keyboard.pressed(Key.alt_l):
keyboard.press(Key.tab)
keyboard.release(Key.tab)
time.sleep(0.5) #
mouse.position = joinposn
mouse.click(Button.left)
time.sleep(1) #
keyboard.type(id)
keyboard.press(Key.enter)
keyboard.release(Key.enter)
time.sleep(3.5) #
keyboard.type(password)
keyboard.press(Key.enter)
keyboard.release(Key.enter)
def append(values):
with open(r"passwords.csv", "a") as passwords:
passwords.write(f"{values[0].upper()},{values[1]},{values[2]}\n")
raise SystemExit
def change_pass(values):
subject = values[0].upper()
password = values[1]
with open("passwords.csv", "r") as passwords:
reader = list(csv.reader(passwords))
for row in reader:
if row[0].upper() == subject:
row[2] = password
break
with open("passwords.csv", "w") as asd:
for line in reader:
asd.write(f"{line[0]},{line[1]},{line[2]}\n")
raise SystemExit
def update_pass(path_to_new_pass):
"""updates passwords.csv with data extracted from newPassPath"""
with open(r"passwords.csv", "w") as passwords:
passwords.write("subject,id,password\n")
doc = Document(path_to_new_pass)
for table in doc.tables:
for row in range(1, 8):
subject = table.cell(row, 2).text.strip()
id = table.cell(row, 3).text.strip()
password = table.cell(row, 4).text.strip()
passwords.write(f"{subject},{id},{password}\n")
raise SystemExit
def getjoinposn():
mouse = Mouse_Controller()
print(
"Open zoom and hover the mouse cursor "
'above the "join" button and press <CTRL>.'
)
def get_coord():
with Events() as events:
for event in events:
if event.key == Key.ctrl_l:
posn = mouse.position
return str(posn)[1:-1]
config = configparser.ConfigParser()
config.read("data.ini")
config.set("VALUES", "JOIN", get_coord())
with open("data.ini", "w") as data:
config.write(data)
print("\n>Mouse position successfully recorded!")
input(">Press enter to exit...")
raise SystemExit