-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.py
96 lines (81 loc) · 3.34 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
# https://github.com/serv0id/skipera
import requests
import sys
import config
from loguru import logger
class Skipera(object):
def __init__(self, course):
self.user_id = None
self.course_id = None
self.base_url = config.BASE_URL
self.session = requests.Session()
self.session.headers.update(config.HEADERS)
self.session.cookies.update(config.COOKIES)
self.course = course
if self.get_userid() == 0:
self.login() # implementation pending
def login(self):
logger.debug("Trying to log in using credentials")
r = self.session.post(self.base_url + "login/v3", json={
"code": "",
"email": config.EMAIL,
"password": config.PASSWORD,
"webrequest": True,
})
logger.info(r.content)
def get_userid(self):
r = self.session.get(self.base_url + "adminUserPermissions.v1?q=my").json()
try:
self.user_id = r["elements"][0]["id"]
logger.info("User ID: " + self.user_id)
except KeyError:
if r.get("errorCode"):
logger.error("Error Encountered: " + r["errorCode"])
return 0
return 1
# hierarchy - Modules > Lessons > Items
def get_modules(self):
r = self.session.get(self.base_url
+ f"onDemandCourseMaterials.v2/?q=slug&slug={self.course}&includes=modules").json()
self.course_id = r["elements"][0]["id"]
logger.debug("Course ID: " + self.course_id)
logger.debug("Number of Modules: " + str(len(r["linked"]["onDemandCourseMaterialModules.v1"])))
for x in r["linked"]["onDemandCourseMaterialModules.v1"]:
logger.info(x["name"] + " -- " + x["id"])
def get_items(self):
r = self.session.get(self.base_url + "onDemandCourseMaterials.v2/", params={
"q": "slug",
"slug": self.course,
"includes": "passableItemGroups,passableItemGroupChoices,items,tracks,gradePolicy,gradingParameters",
"fields": "onDemandCourseMaterialItems.v2(name,slug,timeCommitment,trackId)",
"showLockedItems": "true"
}).json()
for video in r["linked"]["onDemandCourseMaterialItems.v2"]:
logger.info("Watching " + video["name"])
self.watch_item(video["id"])
def watch_item(self, item_id):
r = self.session.post(
self.base_url + f"opencourse.v1/user/{self.user_id}/course/{self.course}/item/{item_id}/lecture"
f"/videoEvents/ended?autoEnroll=false",
json={"contentRequestBody": {}}).json()
if r.get("contentResponseBody") is None:
logger.info("Not a watch item! Reading..")
self.read_item(item_id)
def read_item(self, item_id):
r = self.session.post(self.base_url + "onDemandSupplementCompletions.v1", json={
"courseId": self.course_id,
"itemId": item_id,
"userId": int(self.user_id)
})
if "Completed" not in r.text:
logger.error("Item is a survey! Please complete it manually!")
@logger.catch
def main():
if len(sys.argv) < 2:
logger.error("Course slug not specified!")
return
skipera = Skipera(sys.argv[1])
skipera.get_modules()
skipera.get_items()
if __name__ == '__main__':
main()