Skip to content

Commit 02db208

Browse files
committed
Fixed bug when encountering papers in multiple parts
1 parent 6cedc25 commit 02db208

File tree

4 files changed

+47
-10
lines changed

4 files changed

+47
-10
lines changed

README.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,14 @@ I have created a python flask webserver so now a website version of the
55
code can be run, which should be handier than using the command line.
66

77
You can access the scraper at https://examinations.eoin-cr.xyz/ . It
8-
should be fully functional now (and in my opinion is nicer to use than
9-
the examinations.ie website)
8+
should be fully functional now (and in my opinion is nicer to use than
9+
the examinations.ie website)
10+
11+
---
12+
13+
## Updated in this commit
14+
15+
Previously, there would only be a single url string that was kept track of in
16+
the url scraper. However, this would lead to issues when subjects had multiple
17+
papers in one year for the same level and language. To rectify this, I've
18+
loaded the urls into an array instead, and now it works as expected.

script.py

+24-7
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,35 @@ def scrape(subject, paper_type, exam_type, level, year, language):
2828
"MaterialArchive__noTable__sbv__SubjectSelect": subject,
2929
"MaterialArchive__noTable__sbh__SubjectSelect": "id"}
3030
subject_request = requests.post(subject_url, data=subject_data)
31+
print(subject_url)
3132

3233
# print(subject_request.text)
3334
subject_request = subject_request.text.split('\n')
3435
counter = 0
3536
for line in subject_request:
3637
counter += 1
3738

39+
# the reason for making this array is because sometimes there are multiple
40+
# papers for an exam, breaking the old system. Therefore creating an array
41+
# of urls fixes the issue
42+
url_arr = ["", "", "", "", ""]
43+
arr_count = 0
44+
3845
# Just looking for the lines that match the level and language the user wants
3946
# and taking that exam paper
4047
for i in range(counter):
48+
# print(counter)
4149
if language in subject_request[i] and level in subject_request[i]:
42-
url += subject_request[i + 2]
43-
url = url[8:-31]
50+
print(subject_request[i])
51+
print(subject_request[i])
52+
url_arr[arr_count] = subject_request[i + 2]
53+
url_arr[arr_count] = "https://www.examinations.ie/exammaterialarchive/" + url_arr[arr_count][8:-31]
54+
arr_count += 1
4455

45-
if url == "":
46-
return "Unable to find exam paper"
47-
url = "https://www.examinations.ie/exammaterialarchive/" + url
48-
return url
56+
if arr_count == 0:
57+
url_arr[0] = "Unable to find exam paper"
58+
return url_arr
59+
return url_arr
4960

5061

5162
def val_to_display(value):
@@ -87,9 +98,15 @@ def getvalue():
8798
# print(subject)
8899

89100
url = scrape(subject, paper_type, exam_type, level, year, language)
101+
print(url)
90102
# sets the default selected options as the value of the last thing submitted, and display the
91103
# proper name of the input
92-
return render_template('index.html', url=url, S_exam=val_to_display(exam_type), S_lang=val_to_display(language),
104+
105+
# the url1, url2, etc. thing feels like such a bad workaround but it works
106+
# so I'm leaving it in for now
107+
return render_template('index.html', url1=url[0], url2=url[1], url3=url[2], url4=url[3],
108+
url5=url[4], S_exam=val_to_display(exam_type),
109+
S_lang=val_to_display(language),
93110
S_level=val_to_display(level), S_subject=val_to_display(subject),
94111
S_type=val_to_display(paper_type), S_year=year,
95112
S_exam_V=exam_type, S_lang_V=language, S_level_V=level,

static/style.css

Whitespace-only changes.

templates/index.html

+12-1
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,17 @@ <h1>Please enter the information about the paper you want</h1>
173173
</select>
174174
<input type="submit" value="Submit">
175175
</form>
176-
<a href="{{ url }}">{{ url }}</a>
176+
<!--Ehhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh-->
177+
<!--There's definitely a much better way of doing this-->
178+
<a href="{{ url1 }}">{{ url1 }}</a>
179+
<br>
180+
<a href="{{ url2 }}">{{ url2 }}</a>
181+
<br>
182+
<a href="{{ url3 }}">{{ url3 }}</a>
183+
<br>
184+
<a href="{{ url4 }}">{{ url4 }}</a>
185+
<br>
186+
<a href="{{ url5 }}">{{ url5 }}</a>
187+
<br>
177188
</body>
178189
</html>

0 commit comments

Comments
 (0)