-
Notifications
You must be signed in to change notification settings - Fork 1
/
resultfetcher.php
73 lines (58 loc) · 2.63 KB
/
resultfetcher.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
<?php
/**
8O ,`OL 8PPPPPPPPP88OYO. dO ,o. Yb ,OF
dOOb dP`Op dO ,oOP' YO ,OP ,OYO. Yb ,OP
,OP`Ob dO' YO. dO ,oOP' Yb OP OP YO. YO.,OP
dP YO. ,OP YO. d_oOP' Yb dP dP YO Y,_P
dobooo8p d8ooooo8p dYOo._ Yb dO doooooo8o dO
,OP Ob dO' Yb dO `"Ybo. Ob dO' dO' Yb dO
dP `Ob,OP ObdO `YOo. `O,O' ,O' YbdO
dO' YOdP `OYO 'YP `8P OP YYO
DESC : A small script that fetches the even semester 2011 results (SASTRA University)
@author : Vignesh Rajagopalan
**/
$regno = $_REQUEST['reg'];
$ch = curl_init();
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_URL, "http://www.sastra.edu/results2011/");
curl_setopt($ch, CURLOPT_POSTFIELDS, "__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUJNjk1MjY5MDQ5D2QWAgIDD2QWBAIHDzwrAA8BAA8WBB4LXyFEYXRhQm91bmRnHgtfIUl0ZW1Db3VudGZkZAIJDw9kDxAWAWYWARYCHg5QYXJhbWV0ZXJWYWx1ZWUWAWZkZBgBBQxEZXRhaWxzVmlldzEPZ2S5uBAJbk20yOaYSK1hI892sR%2BNVA%3D%3D&__EVENTVALIDATION=%2FwEWAwL3xOupAgLs0bLrBgKM54rGBrse22jFhESkdm9A%2BcmrHsUeYK5F&TextBox1={$regno}&Button1=Submit");
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 (CK) Firefox/3.0.1");
curl_setopt ($ch, CURLOPT_REFERER, "http://www.sastra.edu/results2011/");
curl_setopt ($ch, CURLOPT_HEADER, false);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$string = curl_exec($ch);
curl_close($ch);
/**
* Adding parsing support for Results, to support JSON export
* @author Ashwanth Kumar <ashwanth@ashwanthkumar.in>
* @date 19/06/2011
**/
// Extract the contens out
preg_match("/<td>Reg No<\/td><td>(.+)<\/td>/",$string, $regMatch);
$registerNumber = $regMatch[1];
preg_match("/<td>SGPA<\/td><td>(.*)<\/td>/",$string, $sgMatch);
$sgpaValue = $sgMatch[1];
preg_match("/<td>CGPA<\/td><td>(.*)<\/td>/",$string, $cgMatch);
$cgpaValue = $cgMatch[1];
preg_match("/<td>Result<\/td><td>(.+)<\/td>/",$string, $resMatch);
$courseWiseGrades = (explode(" ",$resMatch[1]));
$course = array();
foreach($courseWiseGrades as $courseGrade) {
$course[] = explode(" ",$courseGrade);
}
/**
* A simple datastructure to export the results content
**/
class Result {
public $registerNumber;
public $course;
public $sgpa;
public $cgpa;
}
$result = new Result;
$result->registerNumber = $registerNumber;
$result->course = $course;
$result->sgpa = $sgpaValue;
$result->cgpa = $cgpaValue;
header("Content-type: application/json");
echo json_encode($result);