@@ -24,31 +24,36 @@ leetcodeClient.getProblems = function(cb) {
2424 if ( e ) return cb ( e ) ;
2525 if ( resp . statusCode !== 200 ) return cb ( 'HTTP failed:' + resp . statusCode ) ;
2626
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 ) {
3030 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' ] )
3838 } ;
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+ } ) ;
4743
4844 return cb ( null , problems ) ;
4945 } ) ;
5046} ;
5147
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+
5257// hacking ;P
5358var aceCtrl = {
5459 init : function ( ) {
0 commit comments