# find -name "* *" -type f | rename 's/ /_/g' # to remove spaces in the directory
import glob
import os
import shutil
lectures_string = """\nSection: 1 0 / 5\nWelcome to Try Django 1.11\n\n 1. Welcome to Try Django 1.11 3:53\n 2. Walkthrough 3:51\n 3. Getting Started with Django 24:08\n 4. For your Reference 2:36\n 5. What Django Does 10:35\n\nSection: 2 0 / 8\nHTML & Django\n\n 6. Rendering HTML 4:44\n 7. Render a Django Template 9:13\n 8. Context in Django Templates 9:17\n 9. Template Inheritance 13:59\n 10. Include Template Tag 6:04\n 11. Reactivate Virtualenv 1:10\n 12. Class Based Views 8:26\n 13. Template View 7:29\n\nSection: 3 0 / 8\nRemembering Things\n\n 14. Remembering things with Models 11:03\n 15. More on Model Fields 8:59\n 16. Displaying Saved Data 9:47\n 17. Understanding QuerySets 9:14\n 18. Generic List View 8:58\n 19. Restaurant Profile Detail 10:15\n 20. SlugField & Unique Slug Generator 7:01\n 21. Signal for Unique Slug 6:37\n\nSection: 4 0 / 19\nForms, Views, Models, and More\n\n 22. Slugs as URL Params 2:22\n 23. Get Single Items from the DB 11:16\n 24. Saving Data the Hard + Wrong Way 18:39\n 25. The Power of Django Forms 9:07\n 26. The Extra Power of Django Model Forms 7:33\n 27. Simple + Effective Validation 12:17\n 28. Letting Users own Data 18:04\n 29. Associate User to Form Data in FBV 5:27\n 30. Associate User to Data in Class Based View 4:39\n 31. Login Required to View 6:01\n 32. LoginView 9:11\n 33. Using Reverse to Shortcut URLS 13:13\n 34. Menu Items App 11:00\n 35. Menu Items Views 16:26\n 36. Limiting Form Field to QuerySet 11:15\n 37. Personalize Items 17:50\n 38. User Profile View 14:13\n 39. Style Profile with Bootstrap 4:01\n 40. Adding a Robust Search 21:30\n\nSection: 5 0 / 5\nHandling Users & Followers\n\n 41. Follow Users 19:59\n 42. Follow Button Form 19:22\n 43. Following Home Page Feed 15:14\n 44. Register View 18:36\n 45. Activation Keys 15:34\n\nSection: 6 0 / 2\nFinal Steps...\n\n 46. Watch & Go Live 1:35\n 47. Thank you! 1:46'
"""
for line in lectures_string.replace("\n\n", "\n").split("\n"):
line = line.replace(" ", "")
if line == "":
continue
if line.startswith("Section"):
section = line.split(" ")[1]
new_section = True
continue
if new_section:
new_section = False
header = ("{}_{}".format(section, line.replace(" ", "_"))).strip()
print("header: {}".format(header))
os.makedirs(header, exist_ok=True)
else:
l = line.split(" ")
index = l[0].replace(".", "")
l = (' '.join(l[1:-1])).replace(" ", "_") + "*"
file_list = glob.glob(l)
if len(file_list) != 1:
print("Error", file_list)
break
old_filename = file_list[0]
new_filename = "./{}/{}_{}".format(header, index, old_filename.replace(",", ""))
print(old_filename, new_filename)
shutil.copyfile(old_filename, new_filename)