Created
September 13, 2021 07:14
-
-
Save TangliziGit/985cad9dea97f8530b5676f676cf07a5 to your computer and use it in GitHub Desktop.
Course Selecting Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const superagent = require("superagent"); | |
const nodemailer = require("nodemailer"); | |
const cookie = '' | |
const pageUrl = "https://yjsxk.nju.edu.cn/yjsxkapp/sys/xsxkapp/xsxkCourse/loadFanCourseInfo.do" | |
const addLessonUrl = "https://yjsxk.nju.edu.cn/yjsxkapp/sys/xsxkapp/xsxkCourse/choiceCourse.do"; | |
const userAgent = "USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36'"; | |
const courseID = ""; | |
const token = ""; | |
const notify = async () => { | |
const transporter = nodemailer.createTransport({ | |
host: 'smtp.qq.com', | |
port: 465, | |
auth: { | |
user: 'tanglizimail@foxmail.com', | |
pass: '' | |
} | |
}); | |
await transporter.sendMail({ | |
from: 'tanglizimail@foxmail.com', | |
to: 'tanglizimail@foxmail.com', | |
subject: 'Course Selecting Notify', | |
html: '<h1>capacity unreached! Quickly!!!</h1>' | |
}); | |
}; | |
const selectCourse = async () => { | |
try { | |
const res = await superagent | |
.get(pageUrl) | |
.set("cookie", cookie) | |
.set("User-Agent", userAgent); | |
const course = JSON.parse(res.text).datas | |
.find(x => x.BJDM === courseID) | |
if (course.KXRS < 165 || course.DQRS < 165) { | |
console.log("capacity <165"); | |
notify(); | |
const result = await superagent | |
.post(addLessonUrl) | |
.set("cookie", cookie) | |
.set("User-Agent", userAgent) | |
.field('bjdm', courseID) | |
.field('lx', 2) | |
.field('csrfToken', token); | |
console.log(result); | |
return true | |
} else { | |
console.log("capacity reached"); | |
return false | |
} | |
} catch (err) { | |
console.log(err); | |
return false; | |
} | |
return false; | |
}; | |
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); | |
(async () => { | |
while (!await selectCourse()) | |
await sleep(5 * 1000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment