@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | use App\Models\ProblemModel; |
| 7 | 7 | use App\Models\CompilerModel; |
| 8 | 8 | use KubAT\PhpSimple\HtmlDomParser; |
| 9 | -use Auth,Requests,Exception; |
|
| 9 | +use Auth, Requests, Exception; |
|
| 10 | 10 | |
| 11 | 11 | class PTA extends CrawlerBase |
| 12 | 12 | { |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | * |
| 18 | 18 | * @return Response |
| 19 | 19 | */ |
| 20 | - public function __construct($action = 'crawl_problem', $con = 'all', $cached = false) |
|
| 20 | + public function __construct($action='crawl_problem', $con='all', $cached=false) |
|
| 21 | 21 | { |
| 22 | 22 | set_time_limit(0); // Pandora's box, engage! |
| 23 | 23 | if ($action=='judge_level') { |
@@ -35,51 +35,51 @@ discard block |
||
| 35 | 35 | public function crawling($conType) |
| 36 | 36 | { |
| 37 | 37 | $start=time(); |
| 38 | - $f = fopen(__DIR__."/pta_status.log", "w") or die("Unable to open file!"); |
|
| 39 | - if ($conType == 'all') { |
|
| 38 | + $f=fopen(__DIR__."/pta_status.log", "w") or die("Unable to open file!"); |
|
| 39 | + if ($conType=='all') { |
|
| 40 | 40 | // Here is the script |
| 41 | 41 | // |
| 42 | 42 | // var a=""; |
| 43 | 43 | // document.querySelectorAll('a[href^="/problem-sets/"]').forEach(v=>{a+=v.href.split("/")[4]+","}) |
| 44 | 44 | // console.log(a); |
| 45 | 45 | |
| 46 | - $conList=[12,13,14,15,16,17,434,994805046380707840,994805148990160896,994805260223102976,994805342720868352]; |
|
| 46 | + $conList=[12, 13, 14, 15, 16, 17, 434, 994805046380707840, 994805148990160896, 994805260223102976, 994805342720868352]; |
|
| 47 | 47 | } else { |
| 48 | 48 | $conList=[intval($conType)]; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | foreach ($conList as $con) { |
| 52 | - $this->con = $con; |
|
| 53 | - $this->imgi = 1; |
|
| 52 | + $this->con=$con; |
|
| 53 | + $this->imgi=1; |
|
| 54 | 54 | $problemModel=new ProblemModel(); |
| 55 | - $res = Requests::post("https://pintia.cn/api/problem-sets/$con/exams",[ |
|
| 55 | + $res=Requests::post("https://pintia.cn/api/problem-sets/$con/exams", [ |
|
| 56 | 56 | "Content-Type"=>"application/json" |
| 57 | - ],"{}"); |
|
| 57 | + ], "{}"); |
|
| 58 | 58 | |
| 59 | - if (strpos($res->body, 'PROBLEM_SET_NOT_FOUND') !== false) { |
|
| 59 | + if (strpos($res->body, 'PROBLEM_SET_NOT_FOUND')!==false) { |
|
| 60 | 60 | header('HTTP/1.1 404 Not Found'); |
| 61 | 61 | die(); |
| 62 | 62 | } else { |
| 63 | - $generalDetails=json_decode($res->body,true); |
|
| 64 | - $compilerModel = new CompilerModel(); |
|
| 65 | - $list = $compilerModel->list($this->oid); |
|
| 66 | - $compilers = []; |
|
| 63 | + $generalDetails=json_decode($res->body, true); |
|
| 64 | + $compilerModel=new CompilerModel(); |
|
| 65 | + $list=$compilerModel->list($this->oid); |
|
| 66 | + $compilers=[]; |
|
| 67 | 67 | foreach ($generalDetails['problemSet']['problemSetConfig']['compilers'] as $lcode) { |
| 68 | 68 | foreach ($list as $compiler) { |
| 69 | - if ($compiler['lcode'] == $lcode) { |
|
| 69 | + if ($compiler['lcode']==$lcode) { |
|
| 70 | 70 | array_push($compilers, $compiler['coid']); |
| 71 | 71 | break; |
| 72 | 72 | } |
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | - $this->pro['special_compiler'] = join(',', $compilers); |
|
| 75 | + $this->pro['special_compiler']=join(',', $compilers); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | $now=time()-$start; |
| 79 | 79 | fwrite($f, "General Detail API Success at {$now}".PHP_EOL); |
| 80 | 80 | |
| 81 | - $probLists = json_decode(Requests::get( |
|
| 82 | - "https://pintia.cn/api/problem-sets/$con/problems?type=PROGRAMMING&exam_id=0",[ |
|
| 81 | + $probLists=json_decode(Requests::get( |
|
| 82 | + "https://pintia.cn/api/problem-sets/$con/problems?type=PROGRAMMING&exam_id=0", [ |
|
| 83 | 83 | "Content-Type"=>"application/json" |
| 84 | 84 | ] |
| 85 | 85 | )->body, true)["problemSetProblems"]; |
@@ -88,8 +88,8 @@ discard block |
||
| 88 | 88 | fwrite($f, " Problems List API Success at {$now}".PHP_EOL); |
| 89 | 89 | |
| 90 | 90 | foreach ($probLists as $prob) { |
| 91 | - $probDetails = json_decode(Requests::get( |
|
| 92 | - "https://pintia.cn/api/problem-sets/$con/problems/{$prob["id"]}?exam_id=0",[ |
|
| 91 | + $probDetails=json_decode(Requests::get( |
|
| 92 | + "https://pintia.cn/api/problem-sets/$con/problems/{$prob["id"]}?exam_id=0", [ |
|
| 93 | 93 | "Content-Type"=>"application/json" |
| 94 | 94 | ] |
| 95 | 95 | )->body, true)["problemSetProblem"]; |
@@ -97,28 +97,28 @@ discard block |
||
| 97 | 97 | $now=time()-$start; |
| 98 | 98 | fwrite($f, " Problem Details API Success at {$now}".PHP_EOL); |
| 99 | 99 | |
| 100 | - $this->pro['pcode'] = 'PTA'.$prob["id"]; |
|
| 101 | - $this->pro['OJ'] = $this->oid; |
|
| 102 | - $this->pro['contest_id'] = $con; |
|
| 103 | - $this->pro['index_id'] = $prob["id"]; |
|
| 104 | - $this->pro['origin'] = "https://pintia.cn/problem-sets/$con/problems/{$prob["id"]}"; |
|
| 105 | - $this->pro['title'] = $prob["title"]; |
|
| 106 | - $this->pro['time_limit'] = $probDetails["problemConfig"]["programmingProblemConfig"]["timeLimit"]; |
|
| 107 | - $this->pro['memory_limit'] = $probDetails["problemConfig"]["programmingProblemConfig"]["memoryLimit"]; |
|
| 108 | - $this->pro['solved_count'] = $prob["acceptCount"]; |
|
| 109 | - $this->pro['input_type'] = 'standard input'; |
|
| 110 | - $this->pro['output_type'] = 'standard output'; |
|
| 111 | - |
|
| 112 | - $this->pro['description'] = str_replace("](~/","](https://images.ptausercontent.com/",$probDetails["content"]); |
|
| 113 | - $this->pro['description'] = str_replace("$$","$",$this->pro['description']); |
|
| 114 | - $this->pro['markdown'] = 1; |
|
| 115 | - $this->pro['tot_score'] = $probDetails["score"]; |
|
| 116 | - $this->pro["partial"] = 1; |
|
| 117 | - $this->pro['input'] = null; |
|
| 118 | - $this->pro['output'] = null; |
|
| 119 | - $this->pro['note'] = null; |
|
| 120 | - $this->pro['sample'] = []; |
|
| 121 | - $this->pro['source'] = $generalDetails["problemSet"]["name"]; |
|
| 100 | + $this->pro['pcode']='PTA'.$prob["id"]; |
|
| 101 | + $this->pro['OJ']=$this->oid; |
|
| 102 | + $this->pro['contest_id']=$con; |
|
| 103 | + $this->pro['index_id']=$prob["id"]; |
|
| 104 | + $this->pro['origin']="https://pintia.cn/problem-sets/$con/problems/{$prob["id"]}"; |
|
| 105 | + $this->pro['title']=$prob["title"]; |
|
| 106 | + $this->pro['time_limit']=$probDetails["problemConfig"]["programmingProblemConfig"]["timeLimit"]; |
|
| 107 | + $this->pro['memory_limit']=$probDetails["problemConfig"]["programmingProblemConfig"]["memoryLimit"]; |
|
| 108 | + $this->pro['solved_count']=$prob["acceptCount"]; |
|
| 109 | + $this->pro['input_type']='standard input'; |
|
| 110 | + $this->pro['output_type']='standard output'; |
|
| 111 | + |
|
| 112 | + $this->pro['description']=str_replace("](~/", "](https://images.ptausercontent.com/", $probDetails["content"]); |
|
| 113 | + $this->pro['description']=str_replace("$$", "$", $this->pro['description']); |
|
| 114 | + $this->pro['markdown']=1; |
|
| 115 | + $this->pro['tot_score']=$probDetails["score"]; |
|
| 116 | + $this->pro["partial"]=1; |
|
| 117 | + $this->pro['input']=null; |
|
| 118 | + $this->pro['output']=null; |
|
| 119 | + $this->pro['note']=null; |
|
| 120 | + $this->pro['sample']=[]; |
|
| 121 | + $this->pro['source']=$generalDetails["problemSet"]["name"]; |
|
| 122 | 122 | |
| 123 | 123 | $problem=$problemModel->pid($this->pro['pcode']); |
| 124 | 124 | |