Skip to content

Commit

Permalink
fixes handling of multimedia level (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
wilddom committed Sep 2, 2017
1 parent 91b5e1e commit 8d6476d
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions Memrise_Course_Importer/memrise.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,9 +637,6 @@ def loadMem(data, memData, pool, fixUrl=lambda url: url):
def loadLevel(self, course, levelIndex):
levelData = self.service.loadLevelData(course.id, levelIndex)

if levelData["success"] == False:
return None

level = Level(levelData["session"]["level"]["id"])
level.index = levelData["session"]["level"]["index"]
level.title = sanitizeName(levelData["session"]["level"]["title"])
Expand Down Expand Up @@ -669,7 +666,7 @@ def loadLevel(self, course, levelIndex):

for userData in levelData["thingusers"]:
level.pool.schedule.add(self.loadScheduleInfo(userData, level.pool))
memData = levelData["mems"].get(unicode(userData["thing_id"]),{}).get(unicode(userData["mem_id"]))
memData = levelData.get("mems", {}).get(unicode(userData["thing_id"]),{}).get(unicode(userData["mem_id"]))
if memData:
level.pool.mems.add(self.loadMem(userData, memData, level.pool, self.service.toAbsoluteMediaUrl))

Expand Down Expand Up @@ -784,7 +781,7 @@ def loadLevelData(self, courseId, levelIndex):
response = self.openWithRetry(levelUrl)
return json.load(response)
except urllib2.HTTPError as e:
if e.code == 404:
if e.code == 404 or e.code == 400:
raise LevelNotFoundError("Level not found: {}".format(levelIndex))
else:
raise
Expand Down

0 comments on commit 8d6476d

Please sign in to comment.