This repository was archived by the owner on Jan 3, 2024. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathDetailsParser.py
More file actions
122 lines (99 loc) · 3.37 KB
/
Copy pathDetailsParser.py
File metadata and controls
122 lines (99 loc) · 3.37 KB
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
"""
DetailsParser.py this is the file that allows us to quickly query the data source:
classes.uoregon.edu specifically the detailed view for any specific subject and crn
combination
Authors:
(RegTools)
Joseph Goh
Mason Sayyadi
Owen McEvoy
Ryan Gurnick
Samuel Lundquist
Priority credit to:
Ryan Gurnick - 2/27/20 Creation
"""
import urllib.request
import Parser
class DetailsParser:
def __init__(self, subject: str, crn: str):
"""
Initializer for the class parser. This will allow a parser to be
specified that will generate a set of tables in the form of lists
of lists
Example Usage:
parser = DetailsParser.DetailsParser("CIS", "12332")
"""
content = "http://classes.uoregon.edu/pls/prod/hwskdhnt.p_viewdetl?term="+subject+"&crn="+crn
with urllib.request.urlopen(content) as response:
html = response.read()
parser = Parser.Parser()
parser.feed(str(html))
self.subject = subject
self.crn = crn
self._parser = parser
self._tables = self._parser.tables
self._intermediateData = None
self._dict = {}
def deleteFormatting(self):
"""
deleteFormatting is here to remove the formatting from the
table design that is provided by classes.uoregon.edu
This will remove headers from each course subsection
This will remove the amount of results from the bottom
This will remove many empty arrays that are to denote formatting
This will NOT remove empty arrays or empty strings that denote
empty fields such as Instructor or Location that are not provided
for some unknown reason.
:return:
Example Usage:
(Continuation of the __init__ example)
parser.deleteFormatting()
"""
del self._tables[:3]
del self._tables[1]
del self._tables[-3:]
del self._tables[-3:-1]
ret_arr = []
for data in self._tables:
ret_arr.append(data)
self._intermediateData = ret_arr
def parseData(self):
"""
This function will take the intermediateData produced after calling the deleteFormatting and
get it into a usable object.
:return:
"""
for key, val in enumerate(self._intermediateData):
data = self._intermediateData[key]
if key == 0:
for k, v in enumerate(data):
if k == 2:
self._dict.update({
"description": data[k][0]
})
if "Prereqs/Comments" in data[k][0]:
self._dict.update({
"prereqs": data[k][1].replace('Prereq: ', '')
})
elif key == 1:
pass
elif key == 2:
pass
def getPrereqs(self):
"""
This function will return just the prerequisites stored
:return:
"""
if 'prereqs' in self._dict.keys():
return self._dict['prereqs']
else:
return ''
def getDescription(self):
"""
This function will return just the description stored
:return:
"""
if 'description' in self._dict.keys():
return self._dict['description']
else:
return ''