@@ -28,24 +28,35 @@ def scrape(subject, paper_type, exam_type, level, year, language):
28
28
"MaterialArchive__noTable__sbv__SubjectSelect" : subject ,
29
29
"MaterialArchive__noTable__sbh__SubjectSelect" : "id" }
30
30
subject_request = requests .post (subject_url , data = subject_data )
31
+ print (subject_url )
31
32
32
33
# print(subject_request.text)
33
34
subject_request = subject_request .text .split ('\n ' )
34
35
counter = 0
35
36
for line in subject_request :
36
37
counter += 1
37
38
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
+
38
45
# Just looking for the lines that match the level and language the user wants
39
46
# and taking that exam paper
40
47
for i in range (counter ):
48
+ # print(counter)
41
49
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
44
55
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
49
60
50
61
51
62
def val_to_display (value ):
@@ -87,9 +98,15 @@ def getvalue():
87
98
# print(subject)
88
99
89
100
url = scrape (subject , paper_type , exam_type , level , year , language )
101
+ print (url )
90
102
# sets the default selected options as the value of the last thing submitted, and display the
91
103
# 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 ),
93
110
S_level = val_to_display (level ), S_subject = val_to_display (subject ),
94
111
S_type = val_to_display (paper_type ), S_year = year ,
95
112
S_exam_V = exam_type , S_lang_V = language , S_level_V = level ,
0 commit comments