|
@@ -42,13 +42,14 @@ struct Login: Encodable {
|
|
|
let cook: String
|
|
|
}
|
|
|
|
|
|
-struct UserInfo: Encodable {
|
|
|
+struct UserInfo: Decodable {
|
|
|
var name: String
|
|
|
var oid: String
|
|
|
var id: String
|
|
|
var xydLink: String
|
|
|
var serviceLink: String
|
|
|
var studyLink: String
|
|
|
+ var tableData: [PurpleDatum]
|
|
|
init() {
|
|
|
name = "-"
|
|
|
oid = "-"
|
|
@@ -56,6 +57,7 @@ struct UserInfo: Encodable {
|
|
|
xydLink = "-"
|
|
|
serviceLink = "-"
|
|
|
studyLink = "-"
|
|
|
+ tableData = []
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -143,13 +145,166 @@ func doLogin(user: String, password: String, action: @escaping (_: Int) -> Void)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-struct DecodableType: Decodable { let url: String }
|
|
|
+// This file was generated from JSON Schema using quicktype, do not modify it directly.
|
|
|
+// To parse the JSON, add this file to your project and do:
|
|
|
+//
|
|
|
+// let welcome = try? JSONDecoder().decode(Welcome.self, from: jsonData)
|
|
|
+
|
|
|
+import Foundation
|
|
|
+
|
|
|
+// MARK: - Welcome
|
|
|
+
|
|
|
+struct Welcome: Codable {
|
|
|
+ let workRests: [WorkREST]
|
|
|
+ let blocks: [Block]
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: - Block
|
|
|
+
|
|
|
+struct Block: Codable {
|
|
|
+ let ownObjID, type: String
|
|
|
+ let name: Name
|
|
|
+ let data: [BlockDatum]
|
|
|
+ let weekMetas: JSONNull?
|
|
|
+
|
|
|
+ enum CodingKeys: String, CodingKey {
|
|
|
+ case ownObjID = "ownObjId"
|
|
|
+ case type, name, data, weekMetas
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: - BlockDatum
|
|
|
+
|
|
|
+struct BlockDatum: Codable {
|
|
|
+ let week: Int
|
|
|
+ let weekMeta: WeekMeta
|
|
|
+ let data: [PurpleDatum]
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: - PurpleDatum
|
|
|
+
|
|
|
+struct PurpleDatum: Codable {
|
|
|
+ let day, lesson: Int
|
|
|
+ let data: [FluffyDatum]
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: - FluffyDatum
|
|
|
+
|
|
|
+struct FluffyDatum: Codable {
|
|
|
+ let timetableID: JSONNull?
|
|
|
+ let className: Name
|
|
|
+ let classID: ClassID
|
|
|
+ let courseName: String
|
|
|
+ let courseID, courseType: Int
|
|
|
+ let placeID: JSONNull?
|
|
|
+ let placeName: PlaceName
|
|
|
+ let placeSn: PlaceSn
|
|
|
+ let teacher: [Teacher]
|
|
|
+ let room: JSONNull?
|
|
|
+ let start, end: String
|
|
|
+ let timeScope: Int
|
|
|
+
|
|
|
+ enum CodingKeys: String, CodingKey {
|
|
|
+ case timetableID = "timetableId"
|
|
|
+ case className
|
|
|
+ case classID = "classId"
|
|
|
+ case courseName
|
|
|
+ case courseID = "courseId"
|
|
|
+ case courseType
|
|
|
+ case placeID = "placeId"
|
|
|
+ case placeName, placeSn, teacher, room, start, end, timeScope
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+enum ClassID: String, Codable {
|
|
|
+ case ac342897 = "AC_342897"
|
|
|
+ case tac8109 = "TAC_8109"
|
|
|
+ case tac8123 = "TAC_8123"
|
|
|
+}
|
|
|
+
|
|
|
+enum Name: String, Codable {
|
|
|
+ case 高一数学P1班 = "高一数学[P]1班"
|
|
|
+ case 高一物理A5班 = "高一物理[A]5班"
|
|
|
+ case 高中2025届11班
|
|
|
+}
|
|
|
+
|
|
|
+enum PlaceName: String, Codable {
|
|
|
+ case 信毅楼408 = "信毅楼4-08"
|
|
|
+ case 信毅楼412 = "信毅楼4-12"
|
|
|
+ case 本班教室
|
|
|
+}
|
|
|
+
|
|
|
+enum PlaceSn: String, Codable {
|
|
|
+ case bxXy408 = " BX-XY-408 "
|
|
|
+ case bxXy410 = " BX-XY-410 "
|
|
|
+ case empty = ""
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: - Teacher
|
|
|
+
|
|
|
+struct Teacher: Codable {
|
|
|
+ let userID: Int
|
|
|
+ let userName: JSONNull?
|
|
|
+ let fullName: String
|
|
|
+ let userNo: JSONNull?
|
|
|
+
|
|
|
+ enum CodingKeys: String, CodingKey {
|
|
|
+ case userID = "userId"
|
|
|
+ case userName, fullName, userNo
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: - WeekMeta
|
|
|
+
|
|
|
+struct WeekMeta: Codable {
|
|
|
+ let morningRead: Bool
|
|
|
+ let night, afternoon, morning, teachingDay: Int
|
|
|
+ let time: [Time]
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: - Time
|
|
|
+
|
|
|
+struct Time: Codable {
|
|
|
+ let seq: Int
|
|
|
+ let start, end: String
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: - WorkREST
|
|
|
+
|
|
|
+struct WorkREST: Codable {
|
|
|
+ let beginTime, endTime, time, lessonName: String
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: - Encode/decode helpers
|
|
|
+
|
|
|
+class JSONNull: Codable, Hashable {
|
|
|
+ public static func == (_: JSONNull, _: JSONNull) -> Bool {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ func hash(into _: inout Hasher) {}
|
|
|
+
|
|
|
+ public init() {}
|
|
|
+
|
|
|
+ public required init(from decoder: Decoder) throws {
|
|
|
+ let container = try decoder.singleValueContainer()
|
|
|
+ if !container.decodeNil() {
|
|
|
+ throw DecodingError.typeMismatch(JSONNull.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Wrong type for JSONNull"))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public func encode(to encoder: Encoder) throws {
|
|
|
+ var container = encoder.singleValueContainer()
|
|
|
+ try container.encodeNil()
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
var Count: Int = 0
|
|
|
|
|
|
func addCompleted(userInfo: UserInfo, action: @escaping (_: UserInfo) -> Void) {
|
|
|
Count += 1
|
|
|
if Count == 3 {
|
|
|
+ print(userInfo.tableData)
|
|
|
action(userInfo)
|
|
|
}
|
|
|
}
|
|
@@ -159,7 +314,7 @@ extension String {
|
|
|
do {
|
|
|
let RE = try NSRegularExpression(pattern: regex, options: options)
|
|
|
let modified = RE.stringByReplacingMatches(in: self, range: NSRange(location: 0, length: count), withTemplate: with)
|
|
|
- return self
|
|
|
+ return modified
|
|
|
} catch {
|
|
|
return "ERR"
|
|
|
}
|
|
@@ -169,7 +324,7 @@ extension String {
|
|
|
do {
|
|
|
let RE = try NSRegularExpression(pattern: regex)
|
|
|
let modified = RE.stringByReplacingMatches(in: self, range: NSRange(location: 0, length: count), withTemplate: with)
|
|
|
- return self
|
|
|
+ return modified
|
|
|
} catch {
|
|
|
return "ERR"
|
|
|
}
|
|
@@ -200,7 +355,15 @@ func getUserInfo(userInfoIn: UserInfo, action: @escaping (_: UserInfo) -> Void)
|
|
|
]
|
|
|
AF.request("https://debug.sdsz.icu/getWeek", method: .post, parameters: tableParam, encoder: JSONParameterEncoder.default, headers: header).responseString { res in
|
|
|
FetchHandler().fetchAny(url: "bxn-timetable/timetable/monitor/homepage/data/student?studentId=\(userInfo.oid)&dateScope=\(res.value ?? "")&_=0") { res in
|
|
|
- print(res)
|
|
|
+ do {
|
|
|
+ let data = res.data(using: String.Encoding.utf8)
|
|
|
+ let table = try! JSONSerialization.jsonObject(with: data!) as? [String: Any]
|
|
|
+ let decoder = JSONDecoder()
|
|
|
+ let kkd = try decoder.decode(Welcome.self, from: data!)
|
|
|
+ userInfo.tableData = kkd.blocks.first?.data.first?.data ?? []
|
|
|
+ } catch {
|
|
|
+ print(error)
|
|
|
+ }
|
|
|
addCompleted(userInfo: userInfo, action: action)
|
|
|
}
|
|
|
}
|