Skip to content

Commit

Permalink
Show courses waiting for evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
qhy040404 committed Jun 23, 2023
1 parent f7c4c89 commit 1c058db
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,15 @@ object URLManager {
const val VOLTIME_POST_URL = "https://www.dutbit.com/apivue/voltime/"
const val VOLTIME_LATEST_URL = "https://www.dutbit.com/apivue/voltime/last-date"

const val EDU_TOP_DOMAIN = "http://jxgl.dlut.edu.cn"
const val EDU_LOGIN_SSO_URL =
"https://sso.dlut.edu.cn/cas/login?service=http%3A%2F%2Fjxgl.dlut.edu.cn%2Fstudent%2Fucas-sso%2Flogin"
const val EDU_CHECK_URL = "http://jxgl.dlut.edu.cn/student/ws/student/home-page/students"
const val EDU_GRADE_INIT_URL = "http://jxgl.dlut.edu.cn/student/for-std/grade/sheet"
const val EDU_COURSE_TABLE_URL = "http://jxgl.dlut.edu.cn/student/for-std/course-table"
const val EDU_EVALUATION_URL = "http://jxgl.dlut.edu.cn/student/for-std/evaluation/summative"
const val EDU_EVALUATION_TOKEN_URL =
"http://jxgl.dlut.edu.cn/evaluation-student-backend/api/v1/evaluation/token-check"

const val WEBVPN_INIT_URL =
"https://api.m.dlut.edu.cn/login?client_id=87b91a9e463df720&redirect_uri=http://webvpn.dlut.edu.cn/login?filter=app&response_type=code&state=11&scope=base_api"
Expand All @@ -62,6 +66,9 @@ object URLManager {
fun getEduGradeUrl(stuId: Int) =
"http://jxgl.dlut.edu.cn/student/for-std/grade/sheet/info/$stuId?semester="

fun getEduEvaluationTaskUrl(semesterId: Int) =
"http://jxgl.dlut.edu.cn/evaluation-student-backend/api/v1/student/summative-evaluation/task/semester/$semesterId"

fun getEduExamsUrl(stuId: Int) =
"http://jxgl.dlut.edu.cn/student/for-std/exam-arrange/info/$stuId"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ data class Semester(
val id: Int,
val name: String,
val courses: List<Grade>,
)
) {
var needsEvaluationTasks = mutableListOf<String>()
}
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class SingleFragment : BaseFragment<FragmentSingleBinding>() {
URLManager.getSeatAvailableUrl(
TimeUtils.getToday("/", false),
roomCode
)
),
)
)
val amList = availableMap.split(",")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract class BaseEduActivity : SimplePageActivity() {

fun initMinor() {
if (GlobalValues.majorStuId == 0 || GlobalValues.minorStuId == 0) {
val initUrl = Requests.get(URLManager.EDU_GRADE_INIT_URL, true)
val initUrl = Requests.get(URLManager.EDU_GRADE_INIT_URL, getUrl = true)
val initData = Requests.get(URLManager.EDU_GRADE_INIT_URL)

if (initUrl.contains("semester-index")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ import com.qhy040404.libraryonetap.utils.AppUtils
import com.qhy040404.libraryonetap.utils.extensions.getString
import com.qhy040404.libraryonetap.utils.extensions.getStringAndFormat
import com.qhy040404.libraryonetap.utils.tools.GradesUtils
import com.qhy040404.libraryonetap.utils.web.CookieJarImpl
import com.qhy040404.libraryonetap.utils.web.Requests
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import me.saket.cascade.CascadePopupMenu
import okhttp3.Headers.Companion.toHeaders
import okhttp3.HttpUrl.Companion.toHttpUrl
import org.json.JSONObject
import java.io.File

Expand Down Expand Up @@ -131,7 +135,27 @@ class GradesActivity : BaseEduActivity(), MenuProvider {
}
}
}
)
).apply {
if (this.courses.isEmpty()) {
delay(500)
val evaluationTasks =
Requests.get(
URLManager.getEduEvaluationTaskUrl(this.id),
mapOf(
"Authorization" to CookieJarImpl.loadForRequest(URLManager.EDU_TOP_DOMAIN.toHttpUrl())
.find { it.name == "student_evaluation_token" }?.value.orEmpty()
).toHeaders()
)
val evalTasksObj = JSONObject(evaluationTasks).optJSONArray("data")!!
for (k in 0 until evalTasksObj.length()) {
val currentTask = evalTasksObj.optJSONObject(k)!!
needsEvaluationTasks.add(
currentTask.optJSONObject("lesson")!!.optJSONObject("course")!!
.optString("nameZh"),
)
}
}
}
)
}
File(dataDir, Constants.LATEST_GRADE_ID).apply {
Expand Down Expand Up @@ -203,7 +227,16 @@ class GradesActivity : BaseEduActivity(), MenuProvider {
semesters.forEach { semester ->
add(Category(semester.name))
if (semester.courses.isEmpty()) {
add(Card(R.string.gr_eval_first.getString()))
if (semester.needsEvaluationTasks.isEmpty()) {
add(Card(R.string.gr_empty.getString()))
} else {
add(
Clickable(
R.string.gr_eval_first.getString(),
semester.needsEvaluationTasks.joinToString()
)
)
}
return@forEach
}
semester.courses.forEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ import com.qhy040404.libraryonetap.utils.encrypt.DesEncryptUtils
import com.qhy040404.libraryonetap.utils.extensions.decode
import com.qhy040404.libraryonetap.utils.extensions.getString
import com.qhy040404.libraryonetap.utils.extensions.substringBetween
import com.qhy040404.libraryonetap.utils.extensions.toJson
import com.qhy040404.libraryonetap.utils.lazy.resettableLazy
import com.qhy040404.libraryonetap.utils.lazy.resettableManager
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import okhttp3.Cookie
import okhttp3.Headers
import okhttp3.Headers.Companion.toHeaders
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.MediaType
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody
import org.json.JSONObject
import java.net.SocketTimeoutException
import java.net.UnknownHostException
import java.util.concurrent.TimeUnit
Expand All @@ -40,6 +46,7 @@ object Requests {

fun get(
url: String,
headers: Headers = mapOf<String, String>().toHeaders(),
getUrl: Boolean = false,
): String {
if (!AppUtils.hasNetwork()) {
Expand All @@ -50,6 +57,11 @@ object Requests {
GlobalValues.netPrompt = Constants.STRING_NULL
val request = Request.Builder()
.url(url)
.apply {
if (headers.size != 0) {
headers(headers)
}
}
.get()
.build()
try {
Expand Down Expand Up @@ -109,6 +121,7 @@ object Requests {
url: String,
form: String,
mediaType: MediaType,
headers: Headers = mapOf<String, String>().toHeaders(),
getUrl: Boolean = false,
): String {
if (!AppUtils.hasNetwork()) {
Expand All @@ -120,6 +133,11 @@ object Requests {
val body = form.toRequestBody(mediaType)
val request = Request.Builder()
.url(url)
.apply {
if (headers.size != 0) {
headers(headers)
}
}
.post(body)
.build()
try {
Expand Down Expand Up @@ -297,9 +315,31 @@ object Requests {
URLManager.EDU_CHECK_URL,
shouldHas = "person"
).also {
initEduEval()
eduInitialized = it
return it
}
}
}

private fun initEduEval() {
val initToken = get(URLManager.EDU_EVALUATION_URL).substringBetween("token=", "';")
val finalToken = post(
URLManager.EDU_EVALUATION_TOKEN_URL,
mapOf("token" to initToken).toJson()!!,
GlobalValues.ctJson
).let {
JSONObject(it).optJSONObject("data")!!.optString("token")
}
val url = URLManager.EDU_TOP_DOMAIN.toHttpUrl()
CookieJarImpl.saveFromResponse(
url,
listOf(
Cookie.Builder().name("student_evaluation_login_way").value("SSO")
.hostOnlyDomain(url.host).build(),
Cookie.Builder().name("student_evaluation_token").value(finalToken)
.hostOnlyDomain(url.host).build()
)
)
}
}

0 comments on commit 1c058db

Please sign in to comment.