Skip to content

Commit

Permalink
feat: retry when failed to get dirs (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
wznmickey authored Sep 23, 2023
1 parent 67f7175 commit 0c863fb
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions canvassyncer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,24 @@ def prepareLocalFiles(self, courseID, folders):
async def getCourseFoldersWithIDHelper(self, page, courseID):
res = {}
url = f"{self.baseUrl}/courses/{courseID}/folders?page={page}"
folders = await self.client.json(url, debug=self.config["debug"])
for folder in folders:
if folder["full_name"].startswith("course files"):
folder["full_name"] = folder["full_name"][len("course files") :]
res[folder["id"]] = folder["full_name"]
if not res[folder["id"]]:
res[folder["id"]] = "/"
res[folder["id"]] = re.sub(r"[\\\:\*\?\"\<\>\|]", "_", res[folder["id"]])
return res
retryTimes = 0
while retryTimes < 5:
try:
folders = await self.client.json(url, debug=self.config["debug"])
for folder in folders:
if folder["full_name"].startswith("course files"):
folder["full_name"] = folder["full_name"][len("course files") :]
res[folder["id"]] = folder["full_name"]
if not res[folder["id"]]:
res[folder["id"]] = "/"
res[folder["id"]] = re.sub(
r"[\\\:\*\?\"\<\>\|]", "_", res[folder["id"]]
)
return res
except Exception as e:
retryTimes = retryTimes + 1
if self.config["debug"]:
print(str(retryTimes) + " time(s) error: " + str(e))

async def getCourseFilesHelper(self, page, courseID, folders):
files = {}
Expand Down

0 comments on commit 0c863fb

Please sign in to comment.