-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathef.js
More file actions
109 lines (94 loc) · 3.54 KB
/
Copy pathef.js
File metadata and controls
109 lines (94 loc) · 3.54 KB
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
import { configDotenv } from 'dotenv'
configDotenv()
import axios from 'axios'
import { errorWrapper, replaceInString } from './utils.js'
import { QUERIES, URLS } from './axios.config.js'
const HEADERS = {
'Content-Type': 'multipart/form-data',
'Authorization': process.env.AUTHORIZATION,
'Cookie': process.env.COOKIE,
'X-Ef-Access': process.env.X_EF_ACCESS
}
const completeStep = errorWrapper(async (stepId) => {
const { data } = await axios.request({
method: 'post',
url: URLS.COMPLETION,
data: {
minutesSpent: Math.floor(Math.random() * (20 - 4 + 1)) + 4,
studentActivityId: stepId,
score: 100,
studyMode: 0
},
headers: {
...HEADERS,
'Content-Type': 'application/json'
}
})
console.log(stepId, !data.length ? 'completed' : 'failed')
}, { exitOnError: false })
const getCurrentLesson = errorWrapper(async () => {
const formData = new FormData();
formData.append('q', QUERIES.CURRENT_LESSON)
const { data } = await axios({
method: 'post',
url: URLS.CURRENT_LESSON,
data: formData,
headers: {
...HEADERS,
'Content-Type': 'multipart/form-data'
}
})
const containingStudentLesson = data.filter(el => el.studentLessonId)
if (!containingStudentLesson.length) throw new Error("Couldn't find next lesson id");
const nextLessonId = containingStudentLesson[0].studentLessonId
const tmpInfo = await getLessonProgress(replaceInString(QUERIES.LESSON_PROGRESS_FAKE, { lessonId: nextLessonId }))
if (!tmpInfo.templateLessonId) throw new Error("Couldn't find next lesson template lesson id");
console.log("Solving", `"${tmpInfo.lessonName}"`)
const templateLessonInfo = await getTemplateLessonInfo(tmpInfo.templateLessonId)
if (!templateLessonInfo.lesson.id) throw new Error("Couldn't find next lesson id");
// get actual lesson progress
const lessonProgress = await getLessonProgress(templateLessonInfo.lesson.id + '.children.progress', true)
const stepIds = lessonProgress.filter(el => el.stepName).map(el => el.children).flat().map(el => el.id.match(/student_activity!(.*)/)[1])
for (const stepId of stepIds) {
await completeStep(stepId)
}
}, { exitOnError: false })
const getLessonProgress = errorWrapper(async (lessonId, returnALl = false) => {
const formData = new FormData();
formData.append('q', lessonId)
const { data } = await axios({
method: 'post',
url: URLS.LESSON_PROGRESS,
data: formData,
headers: {
...HEADERS,
'Content-Type': 'multipart/form-data'
}
})
if (!data.length) throw new Error("Couldn't find lesson progress data");
return returnALl ? data : data[0]
})
const getTemplateLessonInfo = errorWrapper(async (templateLessonId) => {
const formData = new FormData();
formData.append('q', 'pc_student_lesson_map!' + templateLessonId)
const { data } = await axios({
method: 'post',
url: URLS.LESSON_PROGRESS,
data: formData,
headers: {
...HEADERS,
'Content-Type': 'multipart/form-data'
}
})
if (!data.length) throw new Error("Couldn't find template lesson progress data");
return data[0]
})
// get lesson number from arguments
const lessonNumber = process.argv[2] ?? 1
console.log('Going to complete', lessonNumber, 'lesson(s)')
const main = async () => {
for (let i = 0; i < lessonNumber; i++) {
await getCurrentLesson()
}
}
main()