60 lines
1.8 KiB
Python
60 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
技术栈排序和更新脚本
|
|
- 按照技术栈名称的首字母排序
|
|
- 添加新的技术栈项
|
|
"""
|
|
|
|
import json
|
|
import os
|
|
|
|
def sort_and_update_techstack():
|
|
# 文件路径
|
|
file_path = os.path.join(os.path.dirname(__file__), 'data', 'techstack.json')
|
|
|
|
# 读取JSON文件
|
|
with open(file_path, 'r', encoding='utf-8') as f:
|
|
data = json.load(f)
|
|
|
|
# 新添加的技术栈项
|
|
new_items = [
|
|
{
|
|
"name": "Spring",
|
|
"icon": "https://img.shields.io/badge/-Spring-6DB33F?style=flat&logo=spring&logoColor=white",
|
|
"link": "https://spring.io/"
|
|
},
|
|
{
|
|
"name": "Gin",
|
|
"icon": "https://img.shields.io/badge/-Gin-00ADD8?style=flat&logo=go&logoColor=white",
|
|
"link": "https://gin-gonic.com/"
|
|
}
|
|
]
|
|
|
|
# 获取现有项的名称集合,用于检查是否已存在
|
|
existing_names = {item['name'] for item in data['items']}
|
|
|
|
# 添加新项(如果不存在)
|
|
for new_item in new_items:
|
|
if new_item['name'] not in existing_names:
|
|
data['items'].append(new_item)
|
|
print(f"已添加: {new_item['name']}")
|
|
else:
|
|
print(f"已存在,跳过: {new_item['name']}")
|
|
|
|
# 按照名称的首字母排序(不区分大小写)
|
|
data['items'].sort(key=lambda x: x['name'].upper())
|
|
|
|
# 写回文件,保持格式美观
|
|
with open(file_path, 'w', encoding='utf-8') as f:
|
|
json.dump(data, f, ensure_ascii=False, indent=2)
|
|
|
|
print(f"\n排序完成!共 {len(data['items'])} 个技术栈项")
|
|
print("技术栈列表(按首字母排序):")
|
|
for i, item in enumerate(data['items'], 1):
|
|
print(f" {i}. {item['name']}")
|
|
|
|
if __name__ == '__main__':
|
|
sort_and_update_techstack()
|
|
|