code: def update(course=False):
      
      if course:
          with Spinner.context(msg="Updated course metadata.",
                               waitmsg="Updating course metadata."):
              for course in api.get_courses():
                  old = None
                  try:
                      old = Course.get(Course.tid == course["id"])
                  except peewee.DoesNotExist:
                      old = None
                  if old:
                      old.details_url = course["details_url"]
                      old.save()
                      continue
                  Course.create(tid=course["id"], name=course["name"],
                                details_url=course["details_url"])
      else:
          selected = Course.get_selected()
  
          # with Spinner.context(msg="Updated exercise metadata.",
          #                     waitmsg="Updating exercise metadata."):
          print("Updating exercise data.")
          for exercise in api.get_exercises(selected):
              old = None
              try:
                  old = Exercise.byid(exercise["id"])
              except peewee.DoesNotExist:
                  old = None
              if old is not None:
                  old.name = exercise["name"]
                  old.course = selected.id
                  old.is_attempted = exercise["attempted"]
                  old.is_completed = exercise["completed"]
                  old.deadline = exercise.get("deadline")
                  old.is_downloaded = os.path.isdir(old.path())
                  old.return_url = exercise["return_url"]
                  old.zip_url = exercise["zip_url"]
                  old.submissions_url = exercise["exercise_submissions_url"]
                  old.save()
                  download_exercise(old, update=True)
              else:
                  ex = Exercise.create(tid=exercise["id"],
                                       name=exercise["name"],
                                       course=selected.id,
                                       is_attempted=exercise["attempted"],
                                       is_completed=exercise["completed"],
                                       deadline=exercise.get("deadline"),
                                       return_url=exercise["return_url"],
                                       zip_url=exercise["zip_url"],
                                       submissions_url=exercise[("exercise_"
                                                                 "submissions_"
                                                                 "url")])
                  ex.is_downloaded = os.path.isdir(ex.path())
                  ex.save()
docs: Update the data of courses and or exercises from server.