Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue #26 #31

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions canvassyncer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import aiofiles
import aiohttp
from tqdm import tqdm
global droppedCourse
droppedCourse={"courseIDs":[],"courseCodes":[]}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider storing the value inside the class.


__version__ = "2.0.5"
CONFIG_PATH = os.path.join(
Expand Down Expand Up @@ -187,6 +189,7 @@ async def getCourseIdByCourseCodeHelper(self, page, lowerCourseCodes):
if not courses:
return res
for course in courses:
#print(course)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented debug lines should be deleted.

if course.get("course_code", "").lower() in lowerCourseCodes:
res[course["id"]] = course["course_code"]
lowerCourseCodes.remove(course.get("course_code", "").lower())
Expand All @@ -208,10 +211,23 @@ async def getCourseIdByCourseCode(self):
endOfPage = True
self.courseCode.update(item)
page += PAGES_PER_TIME
correct_courseCode = []
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unify the naming style with the project. Use camel case.

for i in self.courseCode:
correct_courseCode.append(self.courseCode[i])
for i in self.config["courseCodes"]:
if i not in correct_courseCode:
if i not in droppedCourse["courseCodes"]:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combine consecutive if with and.

print("course with course code",i,"might be dropped!")
droppedCourse["courseCodes"].append(i)

async def getCourseCodeByCourseIDHelper(self, courseID):
url = f"{self.baseurl}/courses/{courseID}"
sessRes = await self.sessGetJson(url)
#print("this is sessRes:\n ",sessRes)
if "id" not in sessRes.keys():
if courseID not in droppedCourse["courseIDs"]:
print("Course with course ID",courseID,"might be dropped!")
droppedCourse["courseIDs"].append(courseID)
if sessRes.get("course_code") is None:
return
self.courseCode[courseID] = sessRes["course_code"]
Expand Down Expand Up @@ -345,6 +361,7 @@ async def sync(self):
)



def initConfig():
oldConfig = {}
if os.path.exists(CONFIG_PATH):
Expand Down