|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\VirtualCrawler\UVaLive; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Controllers\VirtualCrawler\CrawlerBase; |
|
6
|
|
|
use App\Models\ProblemModel; |
|
7
|
|
|
use KubAT\PhpSimple\HtmlDomParser; |
|
8
|
|
|
use Auth; |
|
9
|
|
|
use Requests; |
|
10
|
|
|
use Exception; |
|
11
|
|
|
|
|
12
|
|
|
class UVaLive extends CrawlerBase |
|
13
|
|
|
{ |
|
14
|
|
|
public $oid=9; |
|
15
|
|
|
/** |
|
16
|
|
|
* Initial |
|
17
|
|
|
* |
|
18
|
|
|
* @return Response |
|
|
|
|
|
|
19
|
|
|
*/ |
|
20
|
|
|
public function __construct($action='crawl_problem', $con='all', $cached=false) |
|
|
|
|
|
|
21
|
|
|
{ |
|
22
|
|
|
set_time_limit(0); // Pandora's box, engage! |
|
23
|
|
|
if ($action=='judge_level') { |
|
24
|
|
|
$this->judge_level(); |
|
25
|
|
|
} else { |
|
26
|
|
|
$this->crawler($con); |
|
27
|
|
|
} |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function judge_level() |
|
31
|
|
|
{ |
|
32
|
|
|
// TODO |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
public function crawler($con) |
|
37
|
|
|
{ |
|
38
|
|
|
$problemModel=new ProblemModel(); |
|
39
|
|
|
if ($con=='all') { |
|
40
|
|
|
$res=Requests::get("https://icpcarchive.ecs.baylor.edu/uhunt/api/p", [], ['timeout'=>600]); |
|
41
|
|
|
$result=json_decode($res->body, true); |
|
42
|
|
|
$info=[]; |
|
43
|
|
|
for ($i=0; $i<count($result); ++$i) { |
|
|
|
|
|
|
44
|
|
|
$info[$result[$i][1]]=[$result[$i][0], $result[$i][2], $result[$i][3], $result[$i][19]]; |
|
45
|
|
|
} |
|
46
|
|
|
ksort($info); |
|
47
|
|
|
foreach ($info as $key=>$value) { |
|
48
|
|
|
$this->pro['pcode']='UvaL'.$key; |
|
49
|
|
|
$this->pro['OJ']=$this->oid; |
|
50
|
|
|
$this->pro['contest_id']=null; |
|
51
|
|
|
$this->pro['index_id']=$value[0]; |
|
52
|
|
|
$this->pro['origin']="https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=".$value[0]; |
|
53
|
|
|
$this->pro['title']=$value[1]; |
|
54
|
|
|
$this->pro['time_limit']=$value[3]; |
|
55
|
|
|
$this->pro['memory_limit']=131072; // Given in elder codes |
|
56
|
|
|
$this->pro['solved_count']=$value[2]; |
|
57
|
|
|
$this->pro['input_type']='standard input'; |
|
58
|
|
|
$this->pro['output_type']='standard output'; |
|
59
|
|
|
$this->pro['description']="<a href=\"/external/gym/UvaL{$key}.pdf\">[Attachment Link]</a>"; |
|
60
|
|
|
$this->pro['input']=''; |
|
61
|
|
|
$this->pro['output']=''; |
|
62
|
|
|
$this->pro['note']=''; |
|
63
|
|
|
$this->pro['sample']=[]; |
|
64
|
|
|
$this->pro['source']='Here'; |
|
65
|
|
|
$this->pro['file']=1; |
|
66
|
|
|
|
|
67
|
|
|
$problem=$problemModel->pid($this->pro['pcode']); |
|
68
|
|
|
|
|
69
|
|
|
if ($problem) { |
|
70
|
|
|
$problemModel->clearTags($problem); |
|
71
|
|
|
$new_pid=$this->update_problem($this->oid); |
|
|
|
|
|
|
72
|
|
|
} else { |
|
73
|
|
|
$new_pid=$this->insert_problem($this->oid); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
// $problemModel->addTags($new_pid, $tag); // not present |
|
77
|
|
|
} |
|
78
|
|
|
$this->data=array_keys($info); |
|
79
|
|
|
} else { |
|
80
|
|
|
$pf=substr($con, 0, strlen($con)-2); |
|
81
|
|
|
$res=Requests::get("https://icpcarchive.ecs.baylor.edu/external/$pf/$con.pdf"); |
|
82
|
|
|
file_put_contents(base_path("public/external/gym/UvaL$con.pdf"), $res->body); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|