-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_readme.py
More file actions
103 lines (76 loc) · 3.43 KB
/
generate_readme.py
File metadata and controls
103 lines (76 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import os
import csv
# 配置赛区和对应的文件
REGIONS = {
"🇺🇸 USA": "data/usa.csv",
"🇬🇧 UK": "data/uk.csv",
"🇻🇳 Vietnam": "data/vietnam.csv",
"🇷🇺 Russia": "data/russia.csv",
"🇰🇷 South Korea": "data/south_korea.csv"
}
def load_csv_to_md(region_name, file_path):
if not os.path.exists(file_path):
# 调试信息:如果文件不存在,直接返回提示
return f"> ⚠️ Data file for {region_name} not found at `{file_path}`. Please ensure the file exists."
rows = []
try:
# 使用 utf-8-sig 处理 Excel 可能导出的 BOM 头
with open(file_path, mode='r', encoding='utf-8-sig') as f:
# 自动识别分隔符(防止有的是分号,有的是逗号)
dialect = csv.Sniffer().sniff(f.read(1024))
f.seek(0)
reader = csv.DictReader(f, dialect=dialect)
# 清理表头空格
reader.fieldnames = [name.strip() for name in reader.fieldnames]
for row in reader:
# 兼容不同大小写的表头
name = row.get('Project Name', row.get('project name', '-')).strip()
desc = row.get('Description', row.get('description', '-')).strip()
tech = row.get('Key Tech', row.get('key tech', '-')).strip()
link = row.get('Link', row.get('link', '-')).strip()
link_md = f"[Repo]({link})" if link.startswith('http') else "-"
rows.append(f"| {name} | {desc} | {tech} | {link_md} |")
if not rows:
return f"> ℹ️ No projects currently listed for {region_name}."
header = "| Project Name | Description | Key Tech | Link |\n| :--- | :--- | :--- | :--- |"
return header + "\n" + "\n".join(rows)
except Exception as e:
return f"> ❌ Error parsing `{file_path}`: {str(e)}"
# 拼接所有赛区
showcase_sections = ""
for name, path in REGIONS.items():
showcase_sections += f"### {name}\n\n{load_csv_to_md(name, path)}\n\n"
# 完整的 README 内容
README_CONTENT = f"""# 📝 SpoonCommunity: Global AI Agent Ecosystem
[](https://github.com/XSpoonAi)
[](#-global-impact)
---
## 🌍 Global Impact
`🇺🇸 USA` | `🇬🇧 UK` | `🇻🇳 Vietnam` | `🇷🇺 Russia` | `🇰🇷 South Korea`
---
## 🤖 Global Hackathon Project Showcase
{showcase_sections}
---
## 📚 Community & Education
| Resource | Link |
| :--- | :--- |
| 🧑💻 **Co-learning** | [Explore ↗️](https://xspoonai.github.io/spoon-colearning/) |
| 🎬 **Workshop** | [Watch ↗️](https://www.youtube.com/playlist?list=PLyHm819ed_KA36Ae2Ug1iUeiA8_N0obcB) |
| 📖 **Cookbook** | [Read ↗️](https://xspoonai.github.io/) |
---
*Last updated by Spoon-Bot.*
"""
with open("README.md", "w", encoding="utf-8") as f:
f.write(README_CONTENT)
print("Process finished.")
# ... (之前的代码保持不变) ...
import datetime
current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# 完整的 README 内容(在底部加个时间戳)
README_CONTENT = f"""# 📝 SpoonCommunity: Global AI Agent Ecosystem
{showcase_sections}
---
*Last updated by Spoon-Bot at: {current_time}*
"""
with open("README.md", "w", encoding="utf-8") as f:
f.write(README_CONTENT)