This program downloads all files of a Stud.IP users current semester.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.8 KiB

  1. import os
  2. import logging as log
  3. from studip import Studip
  4. class Crawler:
  5. def __init__(self, studip):
  6. self.studip = studip
  7. def download_folder(self, folder):
  8. docs = self.studip.get_docs(folder)
  9. for doc in docs:
  10. log.info('found doc ' + doc)
  11. self.studip.download(doc)
  12. def download_folder_rec(self, folder, base_dir):
  13. log.info('crawling folder ' + folder)
  14. self.create_dir(base_dir)
  15. self.download_folder(folder)
  16. subdirs = self.studip.get_subdirs(folder)
  17. os.chdir(base_dir)
  18. for subdir in subdirs:
  19. subdir_name = subdirs[subdir].replace('/', '-')
  20. subdir_path = os.path.join(base_dir, subdir_name)
  21. log.debug(subdir_path)
  22. self.create_dir(subdir_path)
  23. os.chdir(subdir_path)
  24. self.download_folder_rec(subdir, subdir_path)
  25. def download_course(self, course, base_dir):
  26. log.info('crawling course ' + course)
  27. self.create_dir(base_dir)
  28. os.chdir(base_dir)
  29. root = self.studip.get_top_folder(course)
  30. self.download_folder_rec(root, base_dir)
  31. def download_curr_courses(self, base_dir):
  32. log.info('Start crawling all current courses')
  33. self.create_dir(base_dir)
  34. curr_courses = self.studip.get_curr_courses(
  35. self.studip.get_uid(), self.studip.get_curr_semester())
  36. os.chdir(base_dir)
  37. for course in curr_courses:
  38. log.debug('course is ' + curr_courses[course])
  39. course_name = curr_courses[course].replace('/', '-')
  40. path = os.path.join(base_dir, course_name)
  41. self.download_course(course, path)
  42. def create_dir(self, dir):
  43. if not os.path.exists(dir):
  44. log.info('creating folder' + dir)
  45. os.mkdir(dir)