-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv2.py
More file actions
63 lines (50 loc) · 1.77 KB
/
Copy pathv2.py
File metadata and controls
63 lines (50 loc) · 1.77 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
import requests
import logging
import threading
from configs_v2 import *
import time
from datetime import datetime
logging.basicConfig(level=logging.INFO)
targetTime = "2026-02-17 08:45:45"
timeFormat = "%Y-%m-%d %H:%M:%S"
def getTime() -> str:
return time.strftime(timeFormat, time.localtime())
def isOnTime(currentTime: str):
return currentTime == targetTime
def isPastTime(currentTime: str, targetTime: str) -> bool:
current = datetime.strptime(currentTime, timeFormat)
target = datetime.strptime(targetTime, timeFormat)
return current > target
def getRemainingTime(time_str1: str, time_str2: str, time_format: str) -> str:
dt1 = datetime.strptime(time_str1, time_format)
dt2 = datetime.strptime(time_str2, time_format)
delta = dt2 - dt1
total_seconds = abs(delta.total_seconds())
hours = int(total_seconds // 3600)
minutes = int((total_seconds % 3600) // 60)
seconds = int(total_seconds % 60)
return f"{hours:02d}:{minutes:02d}:{seconds:02d}"
def sendRequest(params: dict[str, str|int]) -> None:
url = "https://bjsdbzx.bjbzszxy.cn/xsxk/studentElective/redisStudentSelectCourse.do"
headers = {
"User-Agent": user_agent,
"Cookie": cookie
}
while True:
res = requests.post(url, data=params, headers=headers)
logging.info(f"Course ID: {params['courseId']} : {res.text}")
while True:
if isPastTime(getTime(), targetTime):
break
else:
print(
f"\r{getRemainingTime(getTime(), targetTime, timeFormat)}", flush=True, end="")
continue
for courseId in coursesId:
params = {
"termId": termId,
"courseId": courseId,
"versionNum": versionNum,
"force": force
}
threading.Thread(target=sendRequest, args=(params,)).start()