10.25 脚本 整理2024全年 GITHUB每周热门项目

需求 : 整理2024全年GITHUB热门项目

功能

  1. 一次性 bash 内嵌 Python3 脚本:

  2. 遍历 /.../github-weekly-rank-main/2024/01/ 下全部 *.md

3.把每个文件里的「排名表格」洗成"一 行一个项目"极简清单

4.调用 Moonshot API 生成「中文名+人话说明」

5.结果保存为 .txt (如 2024-01-A GITHUB热门项目#

脚本 (^..^)ノ (^..^)ノ (^._.^)ノ

复制整段(含开头 python3 -x)到终端回车即可跑,无需落盘任何文件

python3 -x <<'EOF'

---------- 唯一需要改的 ----------

API_KEY = "sk-哥们你自己的要是🔑🔑🔑"

ROOT_DIR = "/storage/emulated/0/Android/LLS_2025/Xmind/临时/github-weekly-rank-main/2024"

----------------------------------

import re, pathlib, requests, os, sys, string

ROOT_DIR = pathlib.Path(ROOT_DIR)

url = "https://api.moonshot.cn/v1/chat/completions"

hdr = {"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"}

def call_kimi(text: str) -> str:

prompt = f"""

下面是一段GitHub每周飙升榜Markdown表格,请清洗并按以下严格格式输出:

  1. 每项目压缩成两行:

第一行:序号. 中文一句话名(英文原名)

第二行: 项目地址 , 人话一句话说明(20~40字)

  1. 去掉图标、增长箭头、图片;序号保留;中文名优先。

  2. 不输出任何额外文字,不总结,不空行分段。

{text}

"""

payload = {

"model": "kimi-k2-turbo-preview",

"messages": [{"role": "user", "content": prompt.strip()}],

"temperature": 0.3,

"max_tokens": 4000

}

r = requests.post(url, headers=hdr, json=payload, timeout=120)

r.raise_for_status()

return r.json()["choices"][0]["message"]["content"].strip()

for month_dir in sorted(ROOT_DIR.iterdir()): # 2024/01 2024/02 ...

if not month_dir.is_dir():

continue

year_month = month_dir.name # "01" "02" ...

每月重新从 A 开始

for idx, md_file in enumerate(sorted(month_dir.glob("*.md"))):

letter = string.ascii_uppercase[idx % 26] # A B C ... 每轮循环

save_name = f"2024-{year_month}-{letter} github热门项目.txt"

txt_file = md_file.with_name(save_name) # 同目录换名

if txt_file.exists():

continue

content = md_file.read_text(encoding="utf-8")

table = "\n".join(re.findall(r"^\|.*\|$", content, flags=re.M))

if not table:

print(f"[SKIP] 无表格 {md_file}")

continue

print(f"[DO] {md_file} → {txt_file.name}")

try:

cleaned = call_kimi(table)

txt_file.write_text(cleaned, encoding="utf-8")

print(f"[OK] 已保存 {txt_file}")

except Exception as e:

print(f"[ERR] {md_file} : {e}")

print("全部完成!")

EOF

下面附赠一个文件整理并生成目录脚本

#!/bin/bash

一键合并 2024- 前缀文件,输出目录同 /2024/

复制保存为 merge2024.sh 后直接 bash merge2024.sh 即可

ROOT="/storage/emulated/0/Android/LLS_2025/Xmind/临时/github-weekly-rank-main/2024"

OUT_FILE="$ROOT/2024-github热门项目合集.txt"

cd "$ROOT" || exit

收集所有 2024-*.txt 并按自然顺序排列

mapfile -d '' LIST < <(find . -maxdepth 2 -type f -iname '2024-*.txt' -print0 | sort -zV)

IFS='\\n' LIST=((printf '%s\0' "${LIST[@]}" | tr '\0' '\n'))

{

echo "===== 大纲 ====="

for i in "${!LIST[@]}"; do

printf "%2d. %s\n" ((i+1)) "{LIST[i]#./}"

done

echo

echo "===== 正文 ====="

for f in "${LIST[@]}"; do

echo

echo "--- ${f#./} ⬇️⬇️⬇️⬇️⬇️ ---"

cat "$f"

done

} > "$OUT_FILE"

echo "报告已生成:(realpath "OUT_FILE")"

相关推荐
Ronin3053 小时前
【Linux网络】进程间关系与守护进程
linux·网络·守护进程·进程间关系·前台进程·后台进程
脑洞代码3 小时前
ADXL345 SPI加速度传感器Linux驱动开发笔记
linux·驱动开发·笔记
新子y3 小时前
【小白笔记】 while 与 for + break 的比较分析
笔记·python
油泼辣子多加3 小时前
2025年10月28日Github流行趋势
github
zhilin_tang4 小时前
构建一个完整的Linux物联网设备共享内存程序测试框架
linux·c语言·架构
java_logo4 小时前
Docker 部署银河麒麟(Kylin Linux)全流程教程
linux·运维·阿里云·docker·容器·kylin
kida_yuan4 小时前
【从零开始】17. 中文摘要提取工具
python·算法·数据分析
chinesegf4 小时前
Docker篇2-用python运行项目和docker运行冲突问题
python·docker·容器
ab15969441974 小时前
白嫖 GitHub 当流水线
github