Skip to content

Commit

Permalink
Add a function to get lectures from Artemis
Browse files Browse the repository at this point in the history
  • Loading branch information
yassinsws committed Mar 18, 2024
2 parents bc97236 + a4186c3 commit b0291b1
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/content_service/get_lecture_from_artemis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import requests
import tempfile

DOWNLOAD_BUFFER_SIZE = 8 * 1024


def download_lecture_pdf(base_url: str, unit_id: int) -> tempfile.NamedTemporaryFile:
"""
Download a single lecture unit from Artemis
"""
artemis_url = f"{base_url}/api/v1/public/pyris/data/lecture-units/{unit_id}/pdf"
response = requests.get(artemis_url, stream=True)
if response.status_code != 200:
print(f"Failed to download the file. Status code: {response.status_code}")
raise ConnectionError

temp_file = tempfile.NamedTemporaryFile()
for chunk in response.iter_content(chunk_size=DOWNLOAD_BUFFER_SIZE):
if chunk:
temp_file.write(chunk)
return temp_file

0 comments on commit b0291b1

Please sign in to comment.