@@ -612,50 +612,36 @@ def __init__(self, args):
612
612
self .problem = args ['problem' ]
613
613
super (Codechef , self ).__init__ (args )
614
614
615
+ def _extract (self , data , marker ):
616
+ data_low = data .lower ()
617
+ extracts = []
618
+ idx = data_low .find (marker , 0 )
619
+
620
+ while not idx == - 1 :
621
+ start = data_low .find ('```' , idx )
622
+ end = data_low .find ('```' , start + 3 )
623
+ extracts += [data [start + 3 :end ]]
624
+ idx = data_low .find (marker , end )
625
+
626
+ return [extract .strip () for extract in extracts ]
627
+
615
628
def parse_html (self , req ):
616
629
"""
617
630
Method to parse the html and get test cases
618
631
from a codechef problem
619
632
"""
620
633
try :
621
- data = json .loads (req .text )
622
- soup = bs (data ['body' ], 'html.parser' )
634
+ data = str (json .loads (req .text )['body' ])
623
635
except (KeyError , ValueError ):
624
636
print ('Problem not found..' )
625
637
Utilities .handle_kbd_interrupt (
626
638
self .site , self .contest , self .problem )
627
639
sys .exit (0 )
628
640
629
- test_cases = soup .findAll ('pre' )
630
- formatted_inputs , formatted_outputs = [], []
631
-
632
- input_list = [
633
- '<pre>(.|\n )*<b>Input:?</b>:?' ,
634
- '<b>Output:?</b>(.|\n )+</pre>'
635
- ]
636
-
637
- output_list = [
638
- '<pre>(.|\n )+<b>Output:?</b>:?' ,
639
- '</pre>'
640
- ]
641
-
642
- input_regex = re .compile ('(%s)' % '|' .join (input_list ))
643
- output_regex = re .compile ('(%s)' % '|' .join (output_list ))
644
-
645
- for case in test_cases :
646
- inp = input_regex .sub ('' , str (case ))
647
- out = output_regex .sub ('' , str (case ))
648
-
649
- inp = re .sub ('<[^<]+?>' , '' , inp )
650
- out = re .sub ('<[^<]+?>' , '' , out )
641
+ inputs = self ._extract (data , 'example input' )
642
+ outputs = self ._extract (data , 'example output' )
651
643
652
- formatted_inputs += [inp .strip ()]
653
- formatted_outputs += [out .strip ()]
654
-
655
- # print 'Inputs', formatted_inputs
656
- # print 'Outputs', formatted_outputs
657
-
658
- return formatted_inputs , formatted_outputs
644
+ return inputs , outputs
659
645
660
646
def get_problem_links (self , req ):
661
647
"""
0 commit comments