canvas-download 1.0.0__py3-none-any.whl → 1.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,25 +1,41 @@
1
1
  """
2
- Create a file called login.json with the following:
3
- {
4
- "API_URL": "",
5
- "API_KEY": ""
6
- }
2
+ canvas-download allows you to download files from canvas with a single command.
7
3
  """
8
4
 
9
5
  import json
10
6
  import re
7
+ import sys
11
8
  from datetime import datetime, timezone
12
9
  from pathlib import Path
13
10
 
14
11
  from canvasapi import Canvas
15
12
  from tqdm import tqdm
16
13
 
14
+ if sys.platform == "win32":
15
+ import win32api
16
+ import win32con
17
+
17
18
 
18
19
  def get_valid_filename(filename: str):
19
- return re.sub(r'[<>:"\|\\/\?\*]', " ", filename).strip()
20
+ return re.sub(r'[<>:"\|\\/\?\*]', " ", filename).strip().strip(".")
21
+
20
22
 
21
23
  def main():
22
- contents = Path("login.json").read_text(encoding="utf-8")
24
+ config_dir = Path(".config")
25
+ login_path = config_dir / "login.json"
26
+ if not courses_path.exists():
27
+ courses_path.mkdir()
28
+ if sys.platform == "win32":
29
+ win32api.SetFileAttributes(str(config_dir), win32con.FILE_ATTRIBUTE_HIDDEN)
30
+
31
+ contents = json.dumps({"API_URL": "", "API_KEY": ""}, indent=4)
32
+ login_path.write_text(contents, encoding="utf-8")
33
+ print(
34
+ f"Fill out the details of your canvas login credentials at {login_path} and relaunch this application to continue. Note: '.config' directory is hidden."
35
+ )
36
+ return
37
+
38
+ contents = login_path.read_text(encoding="utf-8")
23
39
  login = json.loads(contents)
24
40
  canvas = Canvas(login["API_URL"], login["API_KEY"])
25
41
 
@@ -34,22 +50,23 @@ def main():
34
50
  if not current_courses:
35
51
  raise LookupError("no enrolled courses found")
36
52
 
37
- config_path = Path("config.json")
53
+ courses_path = config_dir / "courses.json"
38
54
  names_courses = {
39
55
  re.search(r"\w\S+-\S+\w", course.name).group(0).replace("-", " "): course
40
56
  for course in current_courses
41
57
  }
42
- if not config_path.exists():
58
+ if not courses_path.exists():
43
59
  config = {k: "modules" for k in names_courses}
44
- config_path.write_text(json.dumps(config, indent=4), encoding="utf-8")
60
+ courses_path.write_text(json.dumps(config, indent=4), encoding="utf-8")
45
61
  print("Welcome to canvas sync...")
46
62
  print("config.json has been created; change settings if needed")
47
63
  else:
48
- contents = config_path.read_text(encoding="utf-8")
64
+ contents = courses_path.read_text(encoding="utf-8")
49
65
  config = json.loads(contents)
50
66
  # config validation
51
67
  if not all(name in config for name in names_courses) or not all(
52
- val.lower() == "modules" or val.lower() == "files" for val in config.values()
68
+ val.lower() == "modules" or val.lower() == "files"
69
+ for val in config.values()
53
70
  ):
54
71
  raise ValueError("invalid config")
55
72
 
@@ -80,4 +97,4 @@ def main():
80
97
  continue
81
98
  file_path = folder_path / get_valid_filename(file.display_name)
82
99
  if not file_path.exists():
83
- file.download(str(file_path))
100
+ file.download(str(file_path))
@@ -0,0 +1,37 @@
1
+ Metadata-Version: 2.4
2
+ Name: canvas-download
3
+ Version: 1.1.0
4
+ Summary: Downloads Canvas modules/files into a local directory.
5
+ Project-URL: Homepage, https://github.com/suncloudsmoon/canvas-download
6
+ Project-URL: Issues, https://github.com/suncloudsmoon/canvas-download/issues
7
+ Author-email: suncloudsmoon <farsaturn@outlook.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE.txt
10
+ Keywords: canvas,canvas-grab,download,downloader,offline,sync,utility
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Education
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Topic :: Utilities
23
+ Requires-Python: >=3.10
24
+ Requires-Dist: canvasapi>=3.3.0
25
+ Requires-Dist: pywin32; platform_system == 'Windows'
26
+ Requires-Dist: tqdm>=4.67.1
27
+ Description-Content-Type: text/markdown
28
+
29
+ # canvas-download
30
+ canvas-download downloads Canvas modules/files into a local directory for offline access. A file called 'login.json' under the '.config' directory will be created during the first run of the utility, which will require you to fill out the details of your Canvas login credentials. In the second run of the application, '.config/courses.json' will be created by the application and allows you to choose whether to download "files" or "modules" for each course. After those details are filled out, you can simply call 'canvas-download' in the terminal to start the process of downloading files from Canvas.
31
+
32
+ # How to install
33
+ ```
34
+ pip install canvas-download
35
+ ```
36
+ # Support
37
+ If you encounter any particular issue with this application, feel free to reach out by opening an issue.
@@ -0,0 +1,7 @@
1
+ canvas_download/__init__.py,sha256=UYMprX3e0pTWVOXVUNEa0no_Fp0T4sLV5hVQ-LTtm-A,33
2
+ canvas_download/canvas_download.py,sha256=X_1hXEgEcDmHXqa1AT7XatLFSzqeJjHUC0kVMmF33D0,3921
3
+ canvas_download-1.1.0.dist-info/METADATA,sha256=Ba1dB3cYBkbhuq1NM3o19DQoCz09tHiUxwGPDHYRIe0,1979
4
+ canvas_download-1.1.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
5
+ canvas_download-1.1.0.dist-info/entry_points.txt,sha256=BxAmz6cqp2vls7uVmWnkbq1Dek5VrXqLE3vSU9Ozu1M,57
6
+ canvas_download-1.1.0.dist-info/licenses/LICENSE.txt,sha256=5chfP2IKlCssxQ6-2ISz9dbWt-d33GN5K1eS9SAUdto,1069
7
+ canvas_download-1.1.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.27.0
2
+ Generator: hatchling 1.28.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,25 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: canvas-download
3
- Version: 1.0.0
4
- Summary: Automatically downloads Canvas modules/files into a local directory.
5
- Project-URL: Homepage, https://github.com/suncloudsmoon/canvas-download
6
- Project-URL: Issues, https://github.com/suncloudsmoon/canvas-download/issues
7
- Author-email: suncloudsmoon <farsaturn@outlook.com>
8
- License-Expression: MIT
9
- License-File: LICENSE.txt
10
- Keywords: canvas,canvas-grab,download
11
- Classifier: Operating System :: OS Independent
12
- Classifier: Programming Language :: Python :: 3
13
- Requires-Python: >=3.10
14
- Requires-Dist: canvasapi>=3.3.0
15
- Requires-Dist: tqdm>=4.67.1
16
- Description-Content-Type: text/markdown
17
-
18
- # canvas-download
19
- Canvas Download automatically downloads Canvas modules/files into a local directory for offline access. A file called config.json will be created during the first run of the utility and no files will be downloaded in this run. config.json will define whether to download "files" or "modules" for a particular course. To use this command line utility, create the following files as listed below in the same directory as you want the canvas files to be downloaded to.
20
-
21
- ## login.json
22
- {
23
- "API_URL": "",
24
- "API_KEY": ""
25
- }
@@ -1,7 +0,0 @@
1
- canvas_download/__init__.py,sha256=UYMprX3e0pTWVOXVUNEa0no_Fp0T4sLV5hVQ-LTtm-A,33
2
- canvas_download/canvas_download.py,sha256=0ircdZCoyfkq_HO-Va7PgG3atmb6pTDlH5RBPkYTJco,3217
3
- canvas_download-1.0.0.dist-info/METADATA,sha256=NbQXRzi99CPFdgyifdaOI-_2v_fZvMqXSZrWE90VQqs,1185
4
- canvas_download-1.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
5
- canvas_download-1.0.0.dist-info/entry_points.txt,sha256=BxAmz6cqp2vls7uVmWnkbq1Dek5VrXqLE3vSU9Ozu1M,57
6
- canvas_download-1.0.0.dist-info/licenses/LICENSE.txt,sha256=5chfP2IKlCssxQ6-2ISz9dbWt-d33GN5K1eS9SAUdto,1069
7
- canvas_download-1.0.0.dist-info/RECORD,,