Created
December 11, 2023 03:46
-
-
Save simonLeary42/fb69bc923be5d6d8e60c7b08b22a9736 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import os | |
import platform | |
import tempfile | |
import subprocess | |
import urllib.request | |
# https://stackoverflow.com/a/1732454/6307935 | |
def get_links(url:str) -> list[str]: | |
response = urllib.request.urlopen(url) | |
content = response.read().decode("utf8") | |
return re.findall(r"href=['\"]?([^'\" >]+)", content) | |
schedule_url = input("please provide the link to the course's \"schedule\" page: ") | |
with tempfile.NamedTemporaryFile(delete=False, suffix=".html") as temp_file: | |
temp_file_path = temp_file.name | |
lecture_note_urls = [x for x in get_links(schedule_url) if "lecture-notes" in x] | |
for url in lecture_note_urls: | |
with urllib.request.urlopen(url) as response: | |
if response.status == 200: | |
temp_file.write(response.read()) | |
else: | |
print(f"Failed to download \"{url}\"") | |
if platform.system() == 'Darwin': # macOS | |
subprocess.call(('open', temp_file_path)) | |
elif platform.system() == 'Windows': # Windows | |
os.startfile(temp_file_path) | |
else: # linux | |
subprocess.call(('xdg-open', temp_file_path)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment