Skip to content

Commit f2bebca

Browse files
committed
feat: 更新
1 parent 12b2f64 commit f2bebca

File tree

6 files changed

+57
-55
lines changed

6 files changed

+57
-55
lines changed

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ phyExpt(your_id, your_pw).then((res) => {
7878
```js
7979
const { sklCourses } = require("hdu-lis");
8080

81-
// true for all courses (have experiment), if you have changed the phy.hdu.edu.cn's password , you should add an argument phy_pw
82-
sklCourses(your_id, your_pw,true).then((res) => {
81+
sklCourses(your_id, your_pw).then((res) => {
8382
console.log(res);
8483
})
8584
```
@@ -91,8 +90,7 @@ sklCourses(your_id, your_pw,true).then((res) => {
9190
```js
9291
const { sklTodayCourses } = require("hdu-lis");
9392

94-
// true for all courses (have experiment), if you have changed the phy.hdu.edu.cn's password , you should add an argument phy_pw
95-
sklTodayCourses(your_id, your_pw,true).then((res) => {
93+
sklTodayCourses(your_id, your_pw).then((res) => {
9694
console.log(res);
9795
})
9896
```
@@ -104,8 +102,7 @@ sklTodayCourses(your_id, your_pw,true).then((res) => {
104102
```js
105103
const { sklNowCourses } = require("hdu-lis");
106104

107-
// true for all courses (have experiment), if you have changed the phy.hdu.edu.cn's password , you should add an argument phy_pw
108-
sklNowCourses(your_id, your_pw,true).then((res) => {
105+
sklNowCourses(your_id, your_pw).then((res) => {
109106
console.log(res);
110107
})
111108
```

hdu/cas/casLogin.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ async function casLogin(url, username, password) {
3838
if(request.status != 302){
3939
if(request.status == 403 || request.status == 200){
4040
throw new Error('数字杭电登录账户或密码错误');
41+
}else if (request.status == 404){
42+
throw new Error('数字杭电登录网站已关闭');
4143
}else{
4244
throw new Error('casLogin '+request.statusText);
4345
}

hdu/phy/login.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ async function getCookie(){
4040
// get img
4141
const url = "http://phy.hdu.edu.cn/captcha.svl";
4242
const request = await fetch(url);
43+
if(request.status == 404){
44+
throw new Error('大物实验网站已关闭');
45+
}
4346
const img = await request.buffer();
4447
// ocr
4548
const code = await ocr(img);

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hdu-lis",
3-
"version": "1.0.8",
3+
"version": "1.1.1",
44
"description": "lif is short, you need lis:)",
55
"main": "index.js",
66
"scripts": {

skl/course.js

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
const { sklLogin } = require("./login.js");
22
const { getRandomString } = require("../utils/random.js");
33
const fetch = require('node-fetch');
4-
const {phyExpt} = require('../hdu/phy/expt.js');
54
const getChineseDate = require('../utils/date.js');
65

7-
async function sklCourses(username,password,withExpt=false,exptPwd="123456") {
6+
async function sklCourses(username,password) {
87
const token = await sklLogin(username,password)
9-
const date = new Date(getChineseDate().getTime()-(3600*1000*24* (getChineseDate().getDay()-1)));
8+
const date = new Date(getChineseDate().getTime()-(3600*1000*24* ((getChineseDate().getDay()==0?7:getChineseDate().getDay())-1)));
109
const url = "https://skl.hdu.edu.cn/api/course?startTime="+date.getFullYear().toString()+'-'+(date.getMonth()+1).toString()+'-'+date.getDate().toString();
1110
const res = await fetch(url,{
1211
headers: {
@@ -15,60 +14,51 @@ async function sklCourses(username,password,withExpt=false,exptPwd="123456") {
1514
'skl-ticket': getRandomString(21)
1615
}
1716
})
18-
let courses = await res.json();
19-
let map = new Map();
20-
(courses.list).forEach((item,index)=>{
21-
if (!map.has(item.courseName) && item.weekDay!=6 && item.weekDay!=7) {
22-
map.set(item.courseName,item)
23-
}
24-
})
25-
courses.list = [...map.values()];
26-
// 集成大物实验课程
27-
if(!!withExpt){
28-
29-
for(let i in courses.list) {
30-
if(courses.list[i].classRoom=="大学物理实验中心"){
31-
const expts = await phyExpt(username,exptPwd);
32-
const reg = /(.*)/;
33-
expts.forEach((expt,index)=>{
34-
const weekDay = (reg.exec(expt.time))[1];
35-
if(weekDay==courses.week.toString()){
36-
courses.list[i].courseName = expt.course;
37-
courses.list[i].teacherName = expt.teacher;
38-
courses.list[i].classRoom = expt.place;
39-
}
40-
})
41-
}
42-
}
43-
}
44-
return courses
17+
let i = await res.json();
18+
return i;
4519
}
4620

47-
async function sklTodayCourses(username,password,withExpt=false,exptPwd="123456") {
48-
const cousers = (await sklCourses(username,password,withExpt,exptPwd)).list;
49-
const todayCourse = [];
50-
cousers.forEach((course) => {
51-
if(course.weekDay==getChineseDate().getDay()){
52-
todayCourse.push(course);
53-
}
21+
async function sklTodayCourses(username,password) {
22+
const i = (await sklCourses(username,password));
23+
let l = {};
24+
i.list.forEach(o=>{
25+
l[o.courseId] = o
5426
})
55-
// 根据startSection排序
56-
todayCourse.sort((a,b)=>{
57-
return a.startSection-b.startSection
58-
})
59-
return todayCourse
27+
28+
let classes =[]
29+
let detail={}
30+
let active= getChineseDate().getDay()==0?6:getChineseDate().getDay()-1;
31+
32+
function forenoon() {
33+
return classes.filter(t=>t.startSection <= 5 && t.weekDay - 1 === active).sort((t,e)=>t.startSection - e.startSection)
34+
}
35+
function afternoonClasses() {
36+
return classes.filter(t=>t.startSection >= 6 && t.startSection <= 9 && t.weekDay - 1 === active).sort((t,e)=>t.startSection - e.startSection)
37+
}
38+
function nightClasses() {
39+
return classes.filter(t=>t.startSection > 9 && t.weekDay - 1 === active).sort((t,e)=>t.startSection - e.startSection)
40+
}
41+
42+
detail = i;
43+
44+
45+
46+
classes = setCurrentClass(i);
47+
i.list = [...forenoon(),...afternoonClasses(),...nightClasses()];
48+
return i
6049
}
6150

62-
async function sklNowCourses(username,password,withExpt=false,exptPwd="123456") {
63-
const cousers = await sklTodayCourses(username,password,withExpt,exptPwd);
51+
async function sklNowCourses(username,password) {
52+
const cousers = await sklTodayCourses(username,password);
6453
const NowCourse = [];
6554
const startTime = [[8,5],[8,55],[10,0],[10,50],[11,40],[13,30],[14,20],[15,15],[16,5],[18,30]];
66-
cousers.forEach((course) => {
55+
cousers.list.forEach((course) => {
6756
if(compareNowTime(startTime[course.startSection-1])){
6857
NowCourse.push(course);
6958
}
7059
})
71-
return NowCourse
60+
cousers.list = NowCourse;
61+
return cousers
7262
}
7363

7464
function compareNowTime(time){
@@ -82,6 +72,16 @@ function compareNowTime(time){
8272
}
8373
}
8474

75+
function setCurrentClass(t) {
76+
const e = t.week;
77+
return t.list.filter(s=>{
78+
let r = !0;
79+
return s.period === "\u5355" ? r = e % 2 !== 0 : s.period === "\u53CC" && (r = e % 2 === 0),
80+
e >= s.startWeek && e <= s.endWeek && r
81+
}
82+
)
83+
}
84+
8585
module.exports = {
8686
sklCourses,
8787
sklTodayCourses,

0 commit comments

Comments
 (0)