1- var _ = require ( 'underscore' ) ;
21var cheerio = require ( 'cheerio' ) ;
32var request = require ( 'request' ) ;
43
@@ -24,26 +23,18 @@ leetcodeClient.getProblems = function(cb) {
2423 if ( e ) return cb ( e ) ;
2524 if ( resp . statusCode !== 200 ) return cb ( 'HTTP failed:' + resp . statusCode ) ;
2625
27- var $ = cheerio . load ( body ) ;
28- var problems = $ ( '#problemList tbody tr' ) . map ( function ( ) {
29- var tds = $ ( this ) . children ( ) ;
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 ( )
26+ var problems = JSON . parse ( body ) . stat_status_pairs . map ( function ( p ) {
27+ return {
28+ state : p . status || 'None' ,
29+ id : p . stat . question_id ,
30+ name : p . stat . question__title ,
31+ key : p . stat . question__title_slug ,
32+ link : config . PROBLEM_URL . replace ( '$id' , p . stat . question__title_slug ) ,
33+ locked : p . paid_only ,
34+ percent : p . stat . total_acs * 100 / p . stat . total_submitted ,
35+ level : h . levelToName ( p . difficulty . level )
3836 } ;
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 ( ) ;
37+ } ) ;
4738
4839 return cb ( null , problems ) ;
4940 } ) ;
0 commit comments