@@ -240,12 +240,18 @@ private static List<Question> parseQuestion(String str) {
240
240
241
241
translation (questionList );
242
242
243
+ String dayQuestion = questionOfToday ();
244
+
243
245
Collections .sort (questionList , new Comparator <Question >() {
244
246
@ Override
245
247
public int compare (Question arg0 , Question arg1 ) {
246
248
String frontendId0 = arg0 .getFrontendQuestionId ();
247
249
String frontendId1 = arg1 .getFrontendQuestionId ();
248
- if (StringUtils .isNumeric (frontendId0 ) && StringUtils .isNumeric (frontendId1 )) {
250
+ if (frontendId0 .equals (dayQuestion )) {
251
+ return -1 ;
252
+ } else if (frontendId1 .equals (dayQuestion )) {
253
+ return 1 ;
254
+ } else if (StringUtils .isNumeric (frontendId0 ) && StringUtils .isNumeric (frontendId1 )) {
249
255
return Integer .valueOf (frontendId0 ).compareTo (Integer .valueOf (frontendId1 ));
250
256
} else if (StringUtils .isNumeric (frontendId0 )) {
251
257
return -1 ;
@@ -304,6 +310,24 @@ private static void translation(List<Question> questions) {
304
310
}
305
311
}
306
312
313
+ private static String questionOfToday () {
314
+ if (URLUtils .isCn ()) {
315
+ try {
316
+ HttpRequest httpRequest = HttpRequest .post (URLUtils .getLeetcodeGraphql (), "application/json" );
317
+ httpRequest .setBody ("{\" operationName\" :\" questionOfToday\" ,\" variables\" :{},\" query\" :\" query questionOfToday {\\ n todayRecord {\\ n question {\\ n questionFrontendId\\ n questionTitleSlug\\ n __typename\\ n }\\ n lastSubmission {\\ n id\\ n __typename\\ n }\\ n date\\ n userStatus\\ n __typename\\ n }\\ n}\\ n\" }" );
318
+ httpRequest .addHeader ("Accept" , "application/json" );
319
+ HttpResponse response = HttpRequestUtils .executePost (httpRequest );
320
+ if (response == null || response .getStatusCode () != 200 ) {
321
+ return null ;
322
+ } else {
323
+ return JSONObject .parseObject (response .getBody ()).getJSONObject ("data" ).getJSONArray ("todayRecord" ).getJSONObject (0 ).getJSONObject ("question" ).getString ("questionFrontendId" );
324
+ }
325
+ } catch (Exception e1 ) {
326
+ }
327
+ }
328
+ return null ;
329
+ }
330
+
307
331
308
332
private static List <Tag > parseTag (String str ) {
309
333
List <Tag > tags = new ArrayList <Tag >();
@@ -340,9 +364,9 @@ private static List<Tag> parseCategory(String str, String url) {
340
364
JSONObject object = jsonArray .getJSONObject (i );
341
365
Tag tag = new Tag ();
342
366
tag .setSlug (object .getString ("slug" ));
343
- tag .setType (URLUtils .getLeetcodeUrl () + "/api" + object .getString ("url" ).replace ("problemset" ,"problems" ));
367
+ tag .setType (URLUtils .getLeetcodeUrl () + "/api" + object .getString ("url" ).replace ("problemset" , "problems" ));
344
368
tag .setName (object .getString ("title" ));
345
- if (url .contains (tag .getType ())){
369
+ if (url .contains (tag .getType ())) {
346
370
tag .setSelect (true );
347
371
}
348
372
tags .add (tag );
0 commit comments