diff --git a/README.md b/README.md index 4133b0738e..b94b101512 100644 --- a/README.md +++ b/README.md @@ -360,3 +360,9 @@ docker run -d -p 5000:5000 ghcr.io/anduin2017/how-to-cook:latest - [辅料技巧](./tips/advanced/辅料技巧.md) - [高级专业术语](./tips/advanced/高级专业术语.md) - [油温判断技巧](./tips/advanced/油温判断技巧.md) +## 根据难度星级分类的菜谱 +- [5星级菜谱](./dishes/5star.md) +- [4星级菜谱](./dishes/4star.md) +- [3星级菜谱](./dishes/3star.md) +- [2星级菜谱](./dishes/2star.md) +- [1星级菜谱](./dishes/1star.md) diff --git a/starSystem.py b/starSystem.py new file mode 100644 index 0000000000..3af6c1bca1 --- /dev/null +++ b/starSystem.py @@ -0,0 +1,46 @@ +import os +import sys +import markdown + + + +if sys.version_info[0] >= 3: + unicode = str + +def count_stars(filename: str) -> int: + with open(filename, "r", encoding="UTF-8") as f: + lines = f.readlines() + stars = 0 + for line in lines: + stars += line.count("★") + return stars + +def organize_by_stars(dishes_folder: str) -> None: + dishes = {} + + def process_folder(folder_path: str) -> None: + for filename in os.listdir(folder_path): + filepath = os.path.join(folder_path, filename) + if os.path.isfile(filepath) and filename.endswith(".md"): + stars = count_stars(filepath) + dishes[filepath] = stars + elif os.path.isdir(filepath): + process_folder(filepath) + + # Get absolute path of the dishes folder + base_path = os.path.abspath(dishes_folder) + process_folder(base_path) + + for stars in sorted(set(dishes.values()), reverse=True): + stars_file = os.path.join(base_path, f"{stars}Star.md") + with open(stars_file, "w", encoding="UTF-8") as f: + f.write(f"# Dishes with {stars} Stars\n\n") + for filepath, star_count in dishes.items(): + if star_count == stars: + # Calculate the relative path from the base path + relative_path = os.path.relpath(filepath, start=base_path).replace("\\", "/") + # Correctly format the link for GitHub + f.write(f"* [{os.path.basename(filepath).replace('.md', '')}](./{relative_path})\n") + +dishes_folder = "dishes" +organize_by_stars(dishes_folder)