@@ -24,31 +24,36 @@ leetcodeClient.getProblems = function(cb) {
24
24
if ( e ) return cb ( e ) ;
25
25
if ( resp . statusCode !== 200 ) return cb ( 'HTTP failed:' + resp . statusCode ) ;
26
26
27
- var $ = cheerio . load ( body ) ;
28
- var problems = $ ( '#problemList tbody tr' ) . map ( function ( ) {
29
- var tds = $ ( this ) . children ( ) ;
27
+ var problemsListJson = JSON . parse ( body ) ;
28
+ var problems = [ ] ;
29
+ problemsListJson . stat_status_pairs . forEach ( function ( problemData ) {
30
30
var problem = {
31
- state : $ ( tds [ 0 ] ) . children ( 'span' ) . attr ( 'class' ) ,
32
- id : $ ( tds [ 1 ] ) . text ( ) ,
33
- name : $ ( tds [ 2 ] ) . children ( 'a' ) . text ( ) ,
34
- link : $ ( tds [ 2 ] ) . children ( 'a' ) . attr ( 'href' ) ,
35
- locked : ( $ ( tds [ 2 ] ) . children ( 'i[class="fa fa-lock"]' ) . length === 1 ) ,
36
- percent : $ ( tds [ 3 ] ) . text ( ) ,
37
- level : $ ( tds [ 6 ] ) . text ( )
31
+ state : problemData [ 'status' ] ,
32
+ id : problemData [ 'stat' ] [ 'question_id' ] . toString ( ) ,
33
+ name : problemData [ 'stat' ] [ 'question__title' ] ,
34
+ key : problemData [ 'stat' ] [ 'question__title_slug' ] ,
35
+ link : config . PROBLEM_URL + problemData [ 'stat' ] [ 'question__title_slug' ] ,
36
+ locked : problemData [ 'paid_only' ] ,
37
+ level : parseDifficulty ( problemData [ 'difficulty' ] [ 'level' ] )
38
38
} ;
39
-
40
- // fixup problem attributes
41
- problem . id = parseInt ( problem . id , 10 ) ;
42
- problem . key = _ . last ( _ . compact ( problem . link . split ( '/' ) ) ) ;
43
- problem . link = config . BASE_URL + problem . link ;
44
-
45
- return problem ;
46
- } ) . get ( ) ;
39
+ var percent = parseInt ( problemData [ 'stat' ] [ 'total_acs' ] , 10 ) / parseInt ( problemData [ 'stat' ] [ 'total_submitted' ] , 10 ) * 100 ;
40
+ problem . percent = percent . toFixed ( 1 ) . toString ( ) + '%' ;
41
+ problems . push ( problem ) ;
42
+ } ) ;
47
43
48
44
return cb ( null , problems ) ;
49
45
} ) ;
50
46
} ;
51
47
48
+ function parseDifficulty ( level ) {
49
+ switch ( level ) {
50
+ case 1 : return 'Easy' ;
51
+ case 2 : return 'Medium' ;
52
+ case 3 : return 'Hard' ;
53
+ default : return 'Unknown Difficulty' ;
54
+ }
55
+ }
56
+
52
57
// hacking ;P
53
58
var aceCtrl = {
54
59
init : function ( ) {
0 commit comments