Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README Adding Sort by star system 加入了根据星级分类菜谱系统 #1327

Closed
wants to merge 45 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
1ed6e95
Add files via upload
YufeiJ1ao Jun 4, 2024
16a10b5
Add files via upload
YufeiJ1ao Jun 5, 2024
a031baf
Update README.md
YufeiJ1ao Jun 5, 2024
ad285ec
Delete 1star.md
YufeiJ1ao Jun 5, 2024
964cdf4
Delete 0Star.md
YufeiJ1ao Jun 5, 2024
6bcc3d1
Delete 2star.md
YufeiJ1ao Jun 5, 2024
01e45d6
Delete 3star.md
YufeiJ1ao Jun 5, 2024
719bde0
Delete 4star.md
YufeiJ1ao Jun 5, 2024
58acd8b
Delete 5star.md
YufeiJ1ao Jun 5, 2024
c8e5fe4
Add files via upload
YufeiJ1ao Jun 5, 2024
06a4ba3
Update README.md
YufeiJ1ao Jun 5, 2024
e7351f6
Update README.md
YufeiJ1ao Jun 5, 2024
0df14b5
Update 5star.md
YufeiJ1ao Jun 5, 2024
b2d8137
Delete dishes/2star.md
YufeiJ1ao Jun 5, 2024
2f5bf34
Add files via upload
YufeiJ1ao Jun 5, 2024
57dec32
Delete dishes/1star.md
YufeiJ1ao Jun 5, 2024
f7005fe
Add files via upload
YufeiJ1ao Jun 5, 2024
26b77e1
Delete dishes/2star.md
YufeiJ1ao Jun 5, 2024
4a8d3aa
Add files via upload
YufeiJ1ao Jun 5, 2024
272a450
Delete dishes/1star.md
YufeiJ1ao Jun 5, 2024
80903eb
Add files via upload
YufeiJ1ao Jun 5, 2024
ab87888
Delete dishes/0Star.md
YufeiJ1ao Jun 5, 2024
9371e7d
Delete dishes/3star.md
YufeiJ1ao Jun 5, 2024
92af6db
Add files via upload
YufeiJ1ao Jun 5, 2024
e746934
Delete dishes/4star.md
YufeiJ1ao Jun 5, 2024
a037465
Add files via upload
YufeiJ1ao Jun 5, 2024
6300ba6
Delete dishes/5star.md
YufeiJ1ao Jun 5, 2024
a63aaad
Add files via upload
YufeiJ1ao Jun 5, 2024
b51c8af
Update starSystem.py
YufeiJ1ao Jun 5, 2024
0c3813d
Update 5star.md
YufeiJ1ao Jun 5, 2024
958db4d
Update 4star.md
YufeiJ1ao Jun 5, 2024
bd86d58
Update 3star.md
YufeiJ1ao Jun 5, 2024
2b8135a
Update 2star.md
YufeiJ1ao Jun 5, 2024
1b82a1f
Update 3star.md
YufeiJ1ao Jun 5, 2024
3cc0eb5
Update 1star.md
YufeiJ1ao Jun 5, 2024
d2c45ba
Update 1star.md
YufeiJ1ao Jun 5, 2024
af862de
Update 2star.md
YufeiJ1ao Jun 5, 2024
76501ca
Update 3star.md
YufeiJ1ao Jun 5, 2024
538b13e
Update 4star.md
YufeiJ1ao Jun 5, 2024
f68ce41
Update 5star.md
YufeiJ1ao Jun 5, 2024
a22c668
Delete dishes/1star.md
YufeiJ1ao Jun 5, 2024
2319c48
Delete dishes/2star.md
YufeiJ1ao Jun 5, 2024
4ba0534
Delete dishes/3star.md
YufeiJ1ao Jun 5, 2024
3063816
Delete dishes/4star.md
YufeiJ1ao Jun 5, 2024
3f0e127
Delete dishes/5star.md
YufeiJ1ao Jun 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
46 changes: 46 additions & 0 deletions starSystem.py
Original file line number Diff line number Diff line change
@@ -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)
Loading