Skip to content

Commit

Permalink
初始提交
Browse files Browse the repository at this point in the history
  • Loading branch information
W1ndys committed Feb 3, 2025
0 parents commit 3bd4ba3
Show file tree
Hide file tree
Showing 111 changed files with 26,601 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .cursorrules
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
你是一个 Python开发方面的专家,在生成commit信息方面,你只会用中文语言,并遵循下面模板,在其他方面保持默认。

---

### 提交信息格式模板:

1. 遵循以下模板:
<类型>(<范围>): <简要描述>

2. 指南:

- 每行字符限制为 72 个字符。
- 必须包含 Header;Body 和 Footer 可选。
- 开头使用动词。
- 提供必要的上下文。
- 使用中文书写。

3. 类型:

- feat:新功能
- fix:修复 Bug
- docs:文档更新
- style:代码格式调整(不涉及逻辑变化)
- refactor:代码重构
- test:新增或修改测试
- chore:构建或工具相关更改
58 changes: 58 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Deploy Pages

on:
push:
branches: [ main ] # 或者你的默认分支名
paths:
- 'src/**' # 只有当 src 目录下的文件发生变化时才触发
workflow_dispatch:

jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: write # 添加写入权限
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # 获取完整的 git 历史

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: latest

- name: Install Dependencies
run: |
pnpm config set registry https://registry.npmmirror.com/
pnpm install
- name: Build
run: |
pnpm run docs:build
ls -la # 检查构建输出目录
- name: Deploy
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: src/.vuepress/dist # 修改为正确的构建输出目录
branch: gh-pages
token: ${{ secrets.GITHUB_TOKEN }} # 使用 GitHub 提供的 token
clean: true
force: true

- name: SSH to Server and Run Script
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
password: ${{ secrets.SERVER_PASSWORD }}
script: |
cd /home/W1ndys/Easy-QFNU_scripts/update_site_scripts
chmod +x update_site.sh
./update_site.sh
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
src/.vuepress/.cache
src/.vuepress/.temp
.DS_Store
.vscode
src/.vuepress/dist
86 changes: 86 additions & 0 deletions Easy-QFNU-Scripts/Excel2md/Excel2md.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import pandas as pd
from pypinyin import pinyin, Style
from datetime import datetime


def pinyin_sort(items):
"""按照汉语拼音排序"""
return sorted(
items, key=lambda x: "".join([i[0] for i in pinyin(str(x), style=Style.NORMAL)])
)


def campus_sort(campuses):
"""自定义校区排序,确保曲阜在日照前面"""
campus_priority = {"曲阜": 1, "日照": 2}
return sorted(campuses, key=lambda x: campus_priority.get(x, 999))


def normalize_teacher_name(name):
"""标准化教师名称,处理可能的同音字或错别字"""
name_mapping = {
"名字1": "名字2", # 把名字1换成名字2
"名字3": "名字4", # 把名字3换成名字4
# 可以添加更多的映射关系
}
return name_mapping.get(name, name)


def generate_markdown(data_file):
# 读取Excel文件,不使用第一行作为表头
df = pd.read_excel(data_file, header=None)

# 为列指定名称
df.columns = ["课程名称", "任课老师", "校区", "年份", "老师描述", "提交者昵称"]

# 标准化教师名称
df["任课老师"] = df["任课老师"].apply(normalize_teacher_name)

# 按照拼音对课程名称进行排序
df = df.sort_values(
by=["课程名称"],
key=lambda x: [
"".join([i[0] for i in pinyin(str(item), style=Style.NORMAL)]) for item in x
],
)

# 创建更新日志
update_log = f"## {datetime.now().strftime('%Y-%m-%d')} 更新日志\n\n"

# 收集所有提交者
all_submitters = df["提交者昵称"].tolist()

# 生成markdown文本
markdown = ""

# 遍历每一行数据
for _, row in df.iterrows():
# 添加到更新日志
update_log += f"[{row['课程名称']}]-[{row['校区']}]-[{row['任课老师']}]-[{row['提交者昵称']}]-[{row['年份']}年]\n"

# 生成主要内容
markdown += f"## {row['课程名称']}\n\n"
markdown += f"### {row['校区']}\n\n"
markdown += f"#### {row['任课老师']}\n\n"
markdown += f"{row['老师描述']}\n\n"
markdown += f"> {row['提交者昵称']}({row['年份']}年)\n\n"

update_log += "\n---\n"

return markdown, update_log, all_submitters


# 使用示例
markdown_output, update_log, submitters = generate_markdown("data.xlsx")

# 将主要输出写入文件
with open("output.md", "w", encoding="utf-8") as f:
f.write(markdown_output)

# 将更新日志写入文件
with open("update_log.md", "w", encoding="utf-8") as f:
f.write(update_log)

# 将提交者列表写入文件
with open("submitters.txt", "w", encoding="utf-8") as f:
f.write(",".join(submitters))
174 changes: 174 additions & 0 deletions Easy-QFNU-Scripts/Excel2md/UpdateData.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import pandas as pd
import os
import re


def parse_markdown_file(content):
"""解析markdown文件内容,返回课程、校区、老师的层级结构"""
structure = {}
current_course = None
current_district = None
current_teacher = None

lines = content.split("\n")
for line in lines:
if line.startswith("## "):
current_course = line[3:].strip()
structure[current_course] = {}
current_district = None
current_teacher = None
elif line.startswith("### "):
current_district = line[4:].strip()
if current_course:
structure[current_course][current_district] = {}
current_teacher = None
elif line.startswith("#### "):
current_teacher = line[5:].strip()
if current_course and current_district:
structure[current_course][current_district][current_teacher] = []

return structure


def find_insertion_point(content, course, district, teacher):
"""找到在文件中插入新内容的位置"""
lines = content.split("\n")
course_pattern = f"## {course}"
district_pattern = f"### {district}"
teacher_pattern = f"#### {teacher}"

# 找到课程、校区、老师的位置
course_found = False
district_found = False
teacher_found = False

for i, line in enumerate(lines):
if line.startswith(course_pattern):
course_found = True
elif course_found and line.startswith(district_pattern):
district_found = True
elif district_found and line.startswith(teacher_pattern):
teacher_found = True
# 找到教师后,继续往下找到最后一条评论
for j in range(i + 1, len(lines)):
if (
lines[j].startswith("##")
or lines[j].startswith("###")
or lines[j].startswith("####")
):
return j
if j == len(lines) - 1:
return j + 1

return -1


def process_data(excel_file, markdown_dir):
# 读取Excel文件
df = pd.read_excel(excel_file, header=None)
df.columns = ["course", "teacher", "district", "year", "description", "submitter"]

rows_to_delete = []
unmatched_rows = set()

# 新增:用于记录更新日志和提交者
update_log = []
submitters = set()

# 遍历markdown文件
for filename in os.listdir(markdown_dir):
if filename.endswith(".md"):
file_path = os.path.join(markdown_dir, filename)
with open(file_path, "r", encoding="utf-8") as f:
content = f.read()

# 解析文件结构
structure = parse_markdown_file(content)
content_modified = False

# 处理每一行Excel数据
for index, row in df.iterrows():
if index in rows_to_delete: # 跳过已经处理过的行
continue

course = row["course"]
district = row["district"]
teacher = row["teacher"]

# 检查是否存在对应的结构
if (
course in structure
and district in structure[course]
and teacher in structure[course][district]
):

# 找到插入点
insert_point = find_insertion_point(
content, course, district, teacher
)
if insert_point != -1:
# 构建新内容
new_content = f"\n{row['description']}\n\n> {row['submitter']}({row['year']}年)\n"

# 插入新内容
content_lines = content.split("\n")
content_lines.insert(insert_point, new_content)
content = "\n".join(content_lines)

# 标记要删除的行
rows_to_delete.append(index)
unmatched_rows.discard(index)
content_modified = True

# 新增:记录更新日志和提交者
update_log.append(
f"【{course}】-【{district}】-【{teacher}】-【{row['year']}】"
)
submitters.add(row["submitter"])

print(
f"✅ 成功添加: 【{course}】-【{district}】-【{teacher}】-【{row['submitter']}】"
)
else:
# 只有当这行数据还没有被成功处理时,才标记为未匹配
if index not in rows_to_delete:
unmatched_rows.add(index)

# 只有在文件被修改时才写回
if content_modified:
with open(file_path, "w", encoding="utf-8") as f:
f.write(content)

# 打印未匹配的数据
if unmatched_rows:
print("\n❌ 以下数据未找到匹配位置:")
for index in sorted(unmatched_rows):
row = df.iloc[index]
print(
f"- {row['course']} - {row['district']} - {row['teacher']} - {row['submitter']}"
)

# 删除已处理的行
if rows_to_delete:
df = df.drop(rows_to_delete)
df.to_excel(excel_file, index=False, header=False)
print(f"\n📊 统计信息:")
print(f"- 成功处理:{len(rows_to_delete)} 条数据")
print(f"- 未能匹配:{len(unmatched_rows)} 条数据")
print(f"- 总数据量:{len(df) + len(rows_to_delete)} 条数据")

# 新增:生成更新日志文件
if update_log:
with open("update_log.txt", "a", encoding="utf-8") as f:
f.write("\n".join(update_log) + "\n")

with open("submitters.txt", "a", encoding="utf-8") as f:
f.write(", ".join(sorted(submitters)) + "\n")

print("\n📝 更新日志已生成")
print(f"- 更新条目:{len(update_log)} 条")
print(f"- 提交人数:{len(submitters)} 人")


# 使用示例
process_data("data.xlsx", "example")
Binary file added Easy-QFNU-Scripts/Excel2md/data.xlsx
Binary file not shown.
1 change: 1 addition & 0 deletions Easy-QFNU-Scripts/Excel2md/submitters.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
路易十四,叶桑,张洋滋,小猫是全天下最可爱的,匿名,匿名,匿名
11 changes: 11 additions & 0 deletions Easy-QFNU-Scripts/Excel2md/update_log.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## 2025-01-30 更新日志

[工程伦理学]-[曲阜校区]-[刘新]-[路易十四]-[2024年]
[形势与政策]-[曲阜校区]-[杨兴防]-[叶桑]-[2024年]
[美术鉴赏]-[日照校区]-[解艳林]-[张洋滋]-[2024年]
[体育-排舞]-[曲阜校区]-[刘影]-[小猫是全天下最可爱的]-[2024年]
[瑜伽]-[日照校区]-[曹萍]-[匿名]-[2024年]
[形势与政策三]-[曲阜校区]-[肖黎]-[匿名]-[2024年]
[体育-散打]-[曲阜校区]-[张文娟]-[匿名]-[2024年]

---
Loading

0 comments on commit 3bd4ba3

Please sign in to comment.