Skip to content

Commit

Permalink
fix: minor script improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
louneskmt committed May 27, 2023
1 parent 48675cf commit f4438ef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
1 change: 0 additions & 1 deletion resources/podcasts/the-bitcoin-standard/podcast.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: The Bitcoin Standard
host: Saifedean Ammous
language: en

links:
website: https://saifedean.com/podcast
podcast: https://podcasts.apple.com/us/podcast/the-bitcoin-standard-podcast/id1403202032
Expand Down
27 changes: 18 additions & 9 deletions scripts/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import frontmatter

YAML = ruamel.yaml.YAML()
YAML.indent(sequence=4, offset=2)
YAML.indent(mapping=2, sequence=4, offset=2)
YAML.width = 100000

INVALID_CHARS_PATTERN = re.compile(r"[^\w\d_.-]", re.UNICODE)

Expand Down Expand Up @@ -92,7 +93,7 @@ def print_report(self, header: str):
print(f" - {warning}")

if self.errors or self.warnings:
print("\n")
print("")


class Course(ValidationMixin):
Expand Down Expand Up @@ -134,14 +135,15 @@ def validate(self):
if self.data["level"] not in self.LEVELS:
self.errors.append(f"Invalid level: {self.data['level']}")

if not isinstance(self.data["hours"], int):
if "hours" in self.data and not isinstance(self.data["hours"], int):
self.errors.append(f"'hours' should be an integer: {self.data['hours']}")

if not isinstance(self.data["teacher"], str):
if "teacher" in self.data and not isinstance(self.data["teacher"], str):
self.errors.append(f"'teacher' should be a string: {self.data['teacher']}")

if not isinstance(self.data["contributors"], list) or not all(
isinstance(c, str) for c in self.data["contributors"]
if "contributors" in self.data and (
not isinstance(self.data["contributors"], list)
or not all(isinstance(c, str) for c in self.data["contributors"])
):
self.errors.append(
f"'contributors' should be a list of strings: {self.data['contributors']}"
Expand Down Expand Up @@ -258,6 +260,8 @@ def find_and_fix_courses(directory: str):
if os.path.isdir(os.path.join(directory, d))
]

print("πŸ”Ž Checking courses")

for course_dir in course_dirs:
course = Course(course_dir)
course.validate()
Expand All @@ -266,7 +270,7 @@ def find_and_fix_courses(directory: str):
course.save()
course.print_report(f"Course {course_dir.split('/')[-1]}")

print("Finished checking courses")
print("βœ… Finished checking courses\n")


def find_and_fix_podcasts(directory: str):
Expand All @@ -276,18 +280,21 @@ def find_and_fix_podcasts(directory: str):
if os.path.isdir(os.path.join(directory, d))
]

print("πŸ”Ž Checking podcasts")

for podcast_dir in podcast_dirs:
podcast = Podcast(podcast_dir)
podcast.validate()
podcast.fix_order()
podcast.save()
podcast.print_report(f"Podcast {podcast_dir.split('/')[-1]}")

print("Finished checking podcasts")
print("βœ… Finished checking podcasts\n")


def find_and_fix_assets(directory: str):
print("Checking file names")
print("πŸ”Ž Checking file names")

for root, _, files in os.walk(directory):
for file in files:
if file.startswith(".") or "/." in os.path.join(root, file):
Expand All @@ -312,6 +319,8 @@ def find_and_fix_assets(directory: str):
]
replace_in_files(files, file, new_file_name)

print("βœ… Finished checking file names")


if __name__ == "__main__":
directory = "."
Expand Down

0 comments on commit f4438ef

Please sign in to comment.