Skip to content

Commit

Permalink
fix issue BoYanZh#26
Browse files Browse the repository at this point in the history
  • Loading branch information
jackye666 committed Dec 8, 2021
1 parent 6324c7c commit 2633f18
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion canvassyncer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ async def getCourseIdByCourseCodeHelper(self, page, lowerCourseCodes):
if not courses:
return res
for course in courses:
#print(course)
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 +209,41 @@ async def getCourseIdByCourseCode(self):
endOfPage = True
self.courseCode.update(item)
page += PAGES_PER_TIME

with open(".canvassyncer.json","r+") as f:
correct_courseCode = []
for i in self.courseCode:
correct_courseCode.append(self.courseCode[i])
data = json.load(f)
newcourseCodes = []
for i in data["courseCodes"]:
if i not in correct_courseCode:
print("There is problem with course code",i)
print("Deleted from config")
else:
newcourseCodes.append(i)
data["courseCodes"] = newcourseCodes
#print("data:\n",data["courseIDs"])
f.seek(0)
json.dump(data,f)
f.truncate()
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():
print("There is problem with courseID",courseID)
print("Deleted from config!")
with open(".canvassyncer.json","r+") as f:
data = json.load(f)
newcourseIDs = []
for i in data["courseIDs"]:
if i != courseID:
newcourseIDs.append(i)
data["courseIDs"] = newcourseIDs
#print("data:\n",data["courseIDs"])
f.seek(0)
json.dump(data,f)
f.truncate()
if sessRes.get("course_code") is None:
return
self.courseCode[courseID] = sessRes["course_code"]
Expand Down Expand Up @@ -345,6 +377,7 @@ async def sync(self):
)



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

0 comments on commit 2633f18

Please sign in to comment.