dummy-frontend.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import sys
  2. import aggregator
  3. from backends.support import ResourceCategory, ResourceRawHTML
  4. config = {
  5. "Email": sys.argv[2],
  6. "Username": sys.argv[2],
  7. "Password": sys.argv[3],
  8. "School": sys.argv[4]
  9. }
  10. backend = aggregator.load_backend(sys.argv[1])
  11. if not aggregator.authenticate(backend, config):
  12. print("Authentication failed")
  13. sys.exit(1)
  14. def dump_resources(rsrc, count):
  15. if isinstance(rsrc, ResourceCategory):
  16. print((" " * count) + rsrc.name)
  17. for child in rsrc.children:
  18. dump_resources(child, count + 1)
  19. if rsrc.name == "Welcome":
  20. for child in rsrc.contents:
  21. dump_resources(child, count + 1)
  22. elif isinstance(rsrc, ResourceRawHTML):
  23. print((" " * count) + rsrc.name + ": " + rsrc.html)
  24. else:
  25. print((" " * count) + rsrc.name + " (" + type(rsrc).__name__ + ")")
  26. for course in backend.courses:
  27. print(course.title + " by " + course.teacher + " (ID " + course.id + ")")
  28. try:
  29. print("Course grade: " + str(course.grade_summary))
  30. if course.title == "TODO: Don't waste bandwidth":
  31. for category in course.grades:
  32. print(category.name + ": " + str(round(category.mean * 100)) + "%")
  33. for grade in category.grades:
  34. print(".. " + grade.name + ": " + str(round(grade.grade * 100)) + "%")
  35. except AttributeError:
  36. print("Backend does not implement grades")
  37. try:
  38. dump_resources(course.resources, 0)
  39. except AttributeError:
  40. print("Backend does not implement resources")
  41. try:
  42. for task in course.tasks:
  43. print("- " + task.name)
  44. print(task.resources)
  45. except AttributeError:
  46. print("Backend does not implement tasks")
  47. print("----")