@@ -240,12 +240,18 @@ private static List<Question> parseQuestion(String str) {
240240
241241 translation (questionList );
242242
243+ String dayQuestion = questionOfToday ();
244+
243245 Collections .sort (questionList , new Comparator <Question >() {
244246 @ Override
245247 public int compare (Question arg0 , Question arg1 ) {
246248 String frontendId0 = arg0 .getFrontendQuestionId ();
247249 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 )) {
249255 return Integer .valueOf (frontendId0 ).compareTo (Integer .valueOf (frontendId1 ));
250256 } else if (StringUtils .isNumeric (frontendId0 )) {
251257 return -1 ;
@@ -304,6 +310,24 @@ private static void translation(List<Question> questions) {
304310 }
305311 }
306312
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+
307331
308332 private static List <Tag > parseTag (String str ) {
309333 List <Tag > tags = new ArrayList <Tag >();
@@ -340,9 +364,9 @@ private static List<Tag> parseCategory(String str, String url) {
340364 JSONObject object = jsonArray .getJSONObject (i );
341365 Tag tag = new Tag ();
342366 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" ));
344368 tag .setName (object .getString ("title" ));
345- if (url .contains (tag .getType ())){
369+ if (url .contains (tag .getType ())) {
346370 tag .setSelect (true );
347371 }
348372 tags .add (tag );
0 commit comments