This repository has been archived by the owner on Nov 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
45 lines (35 loc) · 1.39 KB
/
main.py
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
# DO NOT USE THIS TO SPAM EXAMINATIONS.IE WITH REQUESTS; USE RESPONSIBLY.
from PyPDF2 import PdfFileMerger, PdfFileReader
from pathlib import Path
import requests
### MODIFY THESE VALUES ###
lang = "EV"
subjects = {"Physics": 21, "Chemistry": 22}
max_year = 2010
min_year = 2007 # 2007 is the lowest possible
### MODIFY THESE VALUES ###
def createDirectories():
for subject in subjects.keys():
Path(f"./Papers/{subject}").mkdir(parents=True, exist_ok=True)
def downloadPapers():
for subject, ident in subjects.items():
for year in range(min_year, max_year+1):
file = Path(f"./Papers/{subject}/{year}.pdf")
# Don't redownload files
if not file.exists():
print(f"Downloading {year} {subject} Paper")
response = requests.get(f"https://www.examinations.ie/archive/exampapers/{year}/LC0{ident}ALP000{lang}.pdf")
print(f"Writing to ./Papers/{subject}/{year}.pdf")
file.write_bytes(response.content)
else:
print(f"./Papers/{subject}/{year}.pdf already exists!")
def mergePapers(): # Assumes papers were downloaded successfully
for subject in subjects.keys():
merger = PdfFileMerger()
for year in range(min_year, max_year+1):
merger.append(PdfFileReader(f"./Papers/{subject}/{year}.pdf"))
merger.write(f"./Papers/{subject}/collection.pdf")
if __name__ == '__main__':
createDirectories()
downloadPapers()
mergePapers()