forked from BNUACM/bnuoj-web-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin_deal_crawl_replay.php
170 lines (158 loc) · 5.65 KB
/
admin_deal_crawl_replay.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
include("conn.php");
include("ext/simple_html_dom.php");
$oj=convert_str($_GET["oj"]);
$cid=convert_str($_GET["cid"]);
$res=array();
function getidbytitle($name,$oj) {
$qname=convert_str($name);
$pid=null;
//echo strtr($name,"'","%");
$name2=strtr($name,array("'"=>"%","\""=>"%"));
list($pid)=mysql_fetch_array(mysql_query("select pid from problem where title='$qname' and vname='$oj'"));
if ($pid==null) list($pid)=mysql_fetch_array(mysql_query("select pid from problem where title like '".$name2."' and vname='$oj'"));
return $pid;
}
function getidbyid($id,$oj) {
$pid=null;
list($pid)=mysql_fetch_array(mysql_query("select pid from problem where vid='$id' and vname='$oj'"));
return $pid;
}
function crawl_zju($cid) {
global $res;
$html=file_get_html("http://acm.zju.edu.cn/onlinejudge/showContestProblems.do?contestId=$cid");
if ($html->find("div.message")!=null) {
$res["result"]=1;
return;
}
$titles=$html->find("table.list td.problemTitle font");
for ($i=0;$i<sizeof($titles);$i++) {
$tname=getidbytitle(trim($titles[$i]->innertext),"ZJU");
if ($tname==null) {
$res["result"]=1;
return;
}
$res["vpid$i"]=$tname;
}
$html=file_get_html("http://acm.zju.edu.cn/onlinejudge/contestInfo.do?contestId=$cid");
$sttime=trim(strstr($html->find(".dateLink",0)->plaintext,"(",true));
$length=$html->find(".contestInfoTable tr", 3)->find("td",1)->plaintext;
$edtime=date("Y-m-d H:i:s",strtotime($sttime)+strtotime($length)-time());
$title=$html->find(".contestInfoTable tr", 1)->find("td",1)->plaintext;
$res["start_time"]=$sttime;
$res["end_time"]=$edtime;
$res["name"]=$title;
$res["description"]=$res["repurl"]="http://acm.zju.edu.cn/onlinejudge/showContestRankList.do?contestId=$cid";
$res["ctype"]="zjuhtml";
$res["result"]=0;
$res["isvirtual"]=0;
}
function hustv_convert($oj) {
if ($oj=="POJ") return "PKU";
if ($oj=="ZOJ") return "ZJU";
return $oj;
}
function crawl_hustv($cid) {
global $res;
$tuCurl=curl_init();
curl_setopt($tuCurl,CURLOPT_URL,"http://acm.hust.edu.cn/vjudge/contest/view.action?cid=$cid");
curl_setopt($tuCurl,CURLOPT_RETURNTRANSFER,1);
curl_setopt($tuCurl,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($tuCurl,CURLOPT_USERAGENT,"BNUOJ, Orz Isun");
$html=curl_exec($tuCurl);
curl_close($tuCurl);
$html=str_get_html($html);
if ($html->find("#viewContest")==null) {
$res["result"]=1;
return;
}
$titles=$html->find("#viewContest td.center a");
for ($i=0;$i<sizeof($titles);$i++) {
//echo $titles[$i]->plaintext;
$oj=strstr($titles[$i]->plaintext," ",true);
$oj=hustv_convert($oj);
$id=trim(strstr($titles[$i]->plaintext," "));
$tname=getidbyid($id,$oj);
if ($tname==null) {
$res["result"]=1;
return;
}
$res["vpid$i"]=$tname;
}
$sttime=date("Y-m-d H:i:s",$html->find("#overview tr",1)->find("td",1)->plaintext/1000);
$edtime=date("Y-m-d H:i:s",$html->find("#overview tr",2)->find("td",1)->plaintext/1000);
$title=trim($html->find("#contest_title",0)->plaintext);
$res["start_time"]=$sttime;
$res["end_time"]=$edtime;
$res["name"]=$title;
$res["description"]=$res["repurl"]="http://acm.hust.edu.cn:8080/judge/data/standing/$cid.json";
$res["ctype"]="hustvjson";
$res["result"]=0;
$res["isvirtual"]=1;
}
function crawl_uestc($cid) {
global $res;
$html=file_get_html("http://acm.uestc.edu.cn/contest.php?cid=$cid");
if ($html->find("div#login_all")!=null) {
$res["result"]=1;
return;
}
$titles=$html->find("div.list ul");
for ($i=0;$i<sizeof($titles);$i++) {
$title=$titles[$i]->find("li a",1);
// echo $title;
if ($title==null) continue;
$tname=getidbytitle(trim($title->innertext),"UESTC");
if ($tname==null) {
$res["result"]=1;
return;
}
$res["vpid$i"]=$tname;
}
$sttime=trim($html->find("#big_title span.h4",0)->plaintext);
$edtime=trim($html->find("#big_title span.h4",1)->plaintext);
$title=trim($html->find("#big_title h2",0)->plaintext);
$res["start_time"]=$sttime;
$res["end_time"]=$edtime;
$res["name"]=$title;
$res["description"]=$res["repurl"]="http://acm.uestc.edu.cn/contest_ranklist.php?cid=$cid";
$res["ctype"]="uestc";
$res["result"]=0;
$res["isvirtual"]=0;
}
function crawl_uva($cid) {
global $res;
$html=file_get_html("http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=13&page=show_contest&contest=$cid");
if ($html->find("h1")!=null) {
$res["result"]=1;
return;
}
$titles=$html->find("div.tabbertab table tr");
for ($i=1;$i<sizeof($titles);$i++) {
$title=$titles[$i]->find("td",1);
// echo $title;
if ($title==null) continue;
$tname=getidbytitle(trim($title->innertext),"UVA");
if ($tname==null) {
$res["result"]=1;
return;
}
$res["vpid".($i-1)]=$tname;
}
$sttime="";
$edtime="";
$title=trim($html->find("div.componentheading",0)->plaintext);
$res["start_time"]=$sttime;
$res["end_time"]=$edtime;
$res["name"]=$title;
$res["description"]=$res["repurl"]="http://uva.onlinejudge.org/index2.php?option=com_onlinejudge&Itemid=13&page=show_contest_standings&contest=$cid";
$res["ctype"]="uva";
$res["result"]=0;
$res["isvirtual"]=0;
}
if ($oj=="ZJU") crawl_zju($cid);
if ($oj=="HUSTV") crawl_hustv($cid);
if ($oj=="UESTC") crawl_uestc($cid);
if ($oj=="UVA") crawl_uva($cid);
echo json_encode($res);
?>