-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
72 lines (59 loc) · 2.17 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
import logins as ac
import base64
import sqlite3
from browserHandler import SetupBrowser
import assignmentHandler
browser = SetupBrowser()
browser.login(ac.ids[0], base64.b64decode(ac.paswds[0]).decode("utf-8"))
assignments = browser.fetch_links()
# Connect to database
conn = sqlite3.connect('assignments1.db')
# Prepare the CREATE TABLE query
tmp = ""
for x in ac.students:
tmp += x + " INTEGER DEFAULT (0), "
tmp = tmp[:-2]
query = "CREATE TABLE IF NOT EXISTS test(ID INTEGER PRIMARY KEY AUTOINCREMENT,Assignments TEXT UNIQUE,{0}" + ");"
query = query.format(tmp)
# Executing query
conn.execute(query)
# Adding Assignment Links to DB
for assignment in assignments:
tmp = "INSERT OR IGNORE INTO test(Assignments) VALUES ('{0}');"
query = tmp.format(assignment['href'])
conn.execute(query)
# Commit Changes to DB
conn.commit()
# Parsing Assignments Per User
tmp = "SELECT Assignments,{0} FROM test"
for index, student in enumerate(ac.students):
query = tmp.format(student)
result = conn.execute(query).fetchall()
print(student)
browser.restart()
browser.login(ac.ids[index], base64.b64decode(ac.paswds[index]).decode("utf-8"))
for row in result:
if row[1] == 0:
browser.visit(row[0])
if browser.get_submission_status() == "Submitted for grading":
tmp2 = "UPDATE test SET {0} = 1 WHERE Assignments = '{1}'"
query2 = tmp2.format(student, row[0])
conn.execute(query2)
conn.commit()
# Main loop to Download
# Fetch all assignments' statuses of all students
# Get Student Names
q = ""
for x in ac.students:
q += x + ","
q = q[:-1]
# Download if one student submitted, and upload across all accounts while dynamically changing filenames, cover pages
# and paraphrasing the assignments
for assignment in assignments:
assignment_link = assignment['href']
tmp = "SELECT {0} FROM test WHERE assignments = '{1}';"
query = tmp.format(q, assignment_link)
result = conn.execute(query).fetchall()
for row in result:
assignmentHandler.download_assignment_student(row, assignment_link)
assignmentHandler.upload_assignment_student(row, assignment_link)