Compare commits
5 Commits
a84509b9bc
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| a738c6db39 | |||
| e1d63d2910 | |||
| 2b2dbddb0b | |||
| 74297401e7 | |||
| 117aa0fdb8 |
@@ -12,7 +12,10 @@ This script was written in python 3.10.4 and the following packages:
|
|||||||
| requests | 2.31.0 |
|
| requests | 2.31.0 |
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
This script should be able to download all file directly linked to in moodle ressources and folders. It is not able to download files from secondary sources.
|
Currently downloads:
|
||||||
|
- ressources
|
||||||
|
- folders
|
||||||
|
- assignments
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
The script is pretty simple to use. Just provide a moodle link and authentication information like this:
|
The script is pretty simple to use. Just provide a moodle link and authentication information like this:
|
||||||
@@ -38,6 +41,5 @@ python main.py -u USER -p PASSWORD -d /moodle -m https://moodlearchive.epfl.ch/2
|
|||||||
| --ignore_extension | -i | mp4 |
|
| --ignore_extension | -i | mp4 |
|
||||||
|
|
||||||
## Planned
|
## Planned
|
||||||
- [ ] Download submission files
|
- [x] Download submission files
|
||||||
- [ ] Create url files for secondary urls
|
- [ ] Create url files for secondary urls
|
||||||
-
|
|
||||||
|
|||||||
27
main.py
27
main.py
@@ -79,6 +79,31 @@ def download_folder(s, activity):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def download_assign(s, activity):
|
||||||
|
r = s.get(activity.url)
|
||||||
|
soup = BeautifulSoup(r.text, 'html.parser')
|
||||||
|
for candidate in soup.find_all("div", {"class": "fileuploadsubmission"}):
|
||||||
|
link = candidate.find("a")
|
||||||
|
url = link["href"].split('?')[0]
|
||||||
|
with s.get(url, stream=True) as r:
|
||||||
|
directory = os.path.join(activity.parent_dir, activity.name)
|
||||||
|
directory = pathvalidate.sanitize_filepath(directory)
|
||||||
|
file = os.path.join(directory, unquote(link.text))
|
||||||
|
file = pathvalidate.sanitize_filepath(file)
|
||||||
|
if not os.path.exists(directory):
|
||||||
|
os.makedirs(directory)
|
||||||
|
if os.path.exists(os.path.join(file)):
|
||||||
|
return True
|
||||||
|
with open(file + ".part", 'wb') as f:
|
||||||
|
for chunk in r.iter_content(chunk_size=8192):
|
||||||
|
f.write(chunk)
|
||||||
|
os.rename(file + ".part", file)
|
||||||
|
if os.path.exists(file + ".part"):
|
||||||
|
os.remove(file + ".part")
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def download_year(target_url: str):
|
def download_year(target_url: str):
|
||||||
s = requests.Session()
|
s = requests.Session()
|
||||||
s = get_moodle_auth_cookie(s, target_url)
|
s = get_moodle_auth_cookie(s, target_url)
|
||||||
@@ -101,6 +126,8 @@ def download_year(target_url: str):
|
|||||||
print("Could not download: ", activity.url)
|
print("Could not download: ", activity.url)
|
||||||
else:
|
else:
|
||||||
print("Could not find: ", activity.url)
|
print("Could not find: ", activity.url)
|
||||||
|
elif activity.type == "assign":
|
||||||
|
download_assign(s, activity)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
BIN
requirement.txt
BIN
requirement.txt
Binary file not shown.
BIN
requirements.txt
Normal file
BIN
requirements.txt
Normal file
Binary file not shown.
Reference in New Issue
Block a user