This repository has been archived by the owner on May 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
this_month.php
186 lines (170 loc) · 4.69 KB
/
this_month.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
/*
Sample request will be like :
http://localhost/project/this_month.php?month=AUG13&lmonth=JULY13&short=COOK37&lshort=COOK23
Old and very bad way to update submissions.. :P
Created by Shivam Khandelwal dated 3rd Sept. 2013
*/
$handle = fopen("time.php", "w");
$content=date("l, F j, Y h:m:s a", strtotime("+0 hours"));
fwrite($handle,$content,strlen($content));
fclose($handle);
include "crawl2.php";
include "connect.php";
function g($string,$start,$end){
preg_match_all('/' . preg_quote($start, '/') . '(.*?)'. preg_quote($end, '/').'/i', $string, $m);
$out = array();
foreach($m[1] as $key => $value){
$type = explode('::',$value);
if(sizeof($type)>1){
if(!is_array($out[$type[0]]))
$out[$type[0]] = array();
$out[$type[0]][] = $type[1];
} else {
if($value=='NA')
{
$value=0;
$out[] = $value;
$out[] = $value;
}
else
{
$out[] = $value;
}
}
}
return $out;
}
function recalculate($user,$month,$lmonth,$short,$lshort)
{
$url="http://www.codechef.com/users/".$user;
$html = file_get_html($url);
$title="";
$res = preg_match("/<title>(.*)<\/title>/siU", $html, $title_matches);
$title = preg_replace('/\s+/', ' ', $title_matches[1]);
$title = trim($title);
$pos = strpos($title, 'User');
if($pos==9)
{
$finding1=g($html,"".$month."</b>: <span>","</span>");
if(array_key_exists(0,$finding1))
{
$names_of_solved=g($finding1[0],'">','</a>');
$i1=1;
$problems1=$names_of_solved[0];
while(array_key_exists($i1,$names_of_solved))
{
$problems1=$problems1.", ".$names_of_solved[$i1];
$i1++;
}
}
else
{
$problems1="Not solved any";
$i1=0;
}
// echo $problems1." Total : ".$i1;
$finding2=g($html,"".$lmonth."</b>: <span>","</span>");
if(array_key_exists(0,$finding2))
{
$names_of_solved=g($finding2[0],'">','</a>');
$i2=1;
$problems2=$names_of_solved[0];
while(array_key_exists($i2,$names_of_solved))
{
$problems2=$problems2.", ".$names_of_solved[$i2];
$i2++;
}
}
else
{
$problems2="Not solved any";
$i2=0;
}
// echo $problems2." Total : ".$i2;
$finding3=g($html,"".$short."</b>: <span>","</span>");
if(array_key_exists(0,$finding3))
{
$names_of_solved=g($finding3[0],'">','</a>');
$i3=1;
$problems3=$names_of_solved[0];
while(array_key_exists($i3,$names_of_solved))
{
$problems3=$problems3.", ".$names_of_solved[$i3];
$i3++;
}
}
else
{
$problems3="Not solved any";
$i3=0;
}
// echo $problems3." Total : ".$i3;
$finding4=g($html,"".$lshort."</b>: <span>","</span>");
if(array_key_exists(0,$finding4))
{
$names_of_solved=g($finding4[0],'">','</a>');
$i4=1;
$problems4=$names_of_solved[0];
while(array_key_exists($i4,$names_of_solved))
{
$problems4=$problems4.", ".$names_of_solved[$i4];
$i4++;
}
}
else
{
$problems4="Not solved any";
$i4=0;
}
// echo $problems4." Total : ".$i4;
$sql="SELECT COUNT(*) as total FROM dynamic WHERE handle='".$user."'";
$retval=mysql_query($sql);
$data=mysql_fetch_assoc($retval);
if($data['total']==0)
{
$sql = "INSERT INTO dynamic
(handle, short, lshort, longg, llong, p1, p2, p3, p4)
VALUES('".$user."',".$i1.", ".$i2.", ".$i3.", ".$i4.",'".$problems1."', '".$problems2."','".$problems3."','".$problems4."')";
echo $sql;
$retval = mysql_query($sql);
return true;
}
else
{
$sql="UPDATE dynamic
SET short=".$i1.", lshort=".$i2.", longg=".$i3.", llong=".$i4.", p1='".$problems1."', p2='".$problems2."', p3='".$problems3."', p4='".$problems4."'
WHERE handle='".$user."'";
echo $sql;
$retval = mysql_query($sql);
return true;
}
}
else
{
//header("Location: add.php?error=1");
return false;
}
}
$month=$_GET['month'];
$lmonth=$_GET['lmonth'];
$short=$_GET['short'];
$lshort=$_GET['lshort'];
//recalculate($user,$month,$lmonth,$short,$lshort);
$sql = "SELECT handle FROM detail";
$result = mysql_query($sql);
if(empty($_GET['work']))
{
echo 'You should learn some more hacking, or try reading more piece of codes..!';
echo "<br>"+realpath('');
}
else
{
while($row = mysql_fetch_assoc($result))
{
if(recalculate($row['handle'],$month,$lmonth,$short,$lshort)==false)
echo 'error in calculating of '.$row['handle'];
echo 'calculated of '.$row['handle']."<br><br><br>";
}
}
?>