-
Notifications
You must be signed in to change notification settings - Fork 1
/
parser.php
116 lines (95 loc) · 3.65 KB
/
parser.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
<?php
/*
This class is responsible for parsing the information and dumping it in the MySQL database
*/
class BetterTMS_Parser
{
function parseTerms($terms)
{
$termArray;
foreach ($terms->find('TD[width=92%]') as $term)
{
$termObject['termname'] = $term->find('a',0)->plaintext;
$termObject['termlink'] = "https://duapp3.drexel.edu/webtms_du/" . $term->find('a',0)->href;
$regex = "/Term=([0-9]{6})/";
$matches;
preg_match($regex,$termObject['termlink'],$matches);
$termObject['termcode'] = $matches[1];
$termArray[] = $termObject;
}
return $termArray;
}
function parseSubjects($subjects)
{
$collegeObject;
foreach($subjects->find('TD[width=300]') as $table)
{
$college['collegename'] = $table->find('FONT[COLOR=800000]',0)->plaintext;
foreach($table->find('a') as $major)
{
$subject['subjectname'] = $major->plaintext;
$subject['subjectlink']= "https://duapp3.drexel.edu/webtms_du/". $major->href;
$regex = "/SubjCode=([A-Z]*)/";
$matches;
preg_match($regex,$subject['subjectlink'],$matches);
$subject['subjectcode'] = $matches[1];
$college['subjects'][] = $subject;
}
$regex = "/CollCode=([A-Z]*)/";
$matches;
preg_match($regex,$college['subjects'][0]['subjectlink'],$matches);
$college['collegecode'] = $matches[1];
$collegeObject[] = $college;
unset($college);
}
return $collegeObject;
}
function parseCourses($courses)
{
$table = $courses->find('table[BGCOLOR=#FFEAC1]',0);
$courses = $table->find('tr');
$courseobject = array
('subjectcode' => '',
'courseno' => '',
'sec' => '',
'crn' => '',
'coursetitle' => '',
'classlink' => ''
);
$coursecollection = array();
for ($i=1;$i < count($courses); $i++)
{
if(@$courses[$i]->find('td',0)->bgcolor == "#999999")
continue;
if(@$courses[$i]->find('td',2)->bgcolor == "#AAAAAA")
continue;
if(@$courses[$i]->find('td',0)->colspan == "2")
{
$courseobject['subjectcode'] = '';
$courseobject['courseno'] = '';
$courseobject['sec'] = trim($courses[$i]->find('td',2)->plaintext);
$courseobject['crn'] = trim($courses[$i]->find('td',3)->plaintext);
$courseobject['classlink'] = "https://duapp3.drexel.edu/webtms_du/" . trim($courses[$i]->find('td',3)->find('p',0)->find('a',0)->href);
$courseobject['coursetitle'] = trim($courses[$i]->find('td',4)->plaintext);
}
else
{
$courseobject['subjectcode'] = trim($courses[$i]->find('td',0)->plaintext);
$courseobject['courseno'] = trim($courses[$i]->find('td',1)->plaintext);
$courseobject['sec'] = trim($courses[$i]->find('td',3)->plaintext);
$courseobject['crn'] = trim($courses[$i]->find('td',4)->plaintext);
$courseobject['classlink'] = "https://duapp3.drexel.edu/webtms_du/" . trim($courses[$i]->find('td',4)->find('p',0)->find('a',0)->href);
$courseobject['coursetitle'] = trim($courses[$i]->find('td',5)->plaintext);
}
if (empty($courseobject['subjectcode']) || $courseobject['subjectcode'] == ' ')
$courseobject['subjectcode'] = $bufferobject['subjectcode'];
if (empty($courseobject['courseno']) || $courseobject['courseno'] == ' ')
$courseobject['courseno'] = $bufferobject['courseno'];
$bufferobject = $courseobject;
$coursecollection[] = $courseobject;
unset($courseobject);
}
return $coursecollection;
}
}
?>