0%

如何优雅地管理 GitHub 上 star 的项目

转载 https://zhuanlan.zhihu.com/p/150889781

如何优雅地管理 GitHub 上 star 的项目

GitHub Star管理工具很多,或是插件,或是网站.我想,纯文本还是最简单的方法,如果把它以一定格式导出来,发布到知乎专栏上可能更方便查看和分享,下面谈做法.

安装PyGithub

pip install PyGithub

导出stars.csv

这里使用github上的export-stars项目来导出. github.com/JeffCarpenter/export-stars

GH_USER=yourGithubusername python3 export_stars.py > stars.csv

由csv文本转markdown格式并用split分割

stars.csv内容例如

1
2
3
4
https://github.com/TheAlgorithms/C,All Algorithms implemented in C 
https://github.com/TheAlgorithms/C-Plus-Plus,All Algorithms implemented in C++
https://github.com/mitmath/1806,18.06 course at MIT
用sed过滤器将其转换为markdown的链接形式,这里用了捕获组这点小知识.
1
sed "s#\(https://github.com/\)\([^,]*\),#- [\2](\1\2)#g" test.txt

转换之后

1
2
3
- [TheAlgorithms/C](https://github.com/TheAlgorithms/C)All Algorithms implemented in C 
- [TheAlgorithms/C-Plus-Plus](https://github.com/TheAlgorithms/C-Plus-Plus)All Algorithms implemented in C++
- [mitmath/1806](https://github.com/mitmath/1806)18.06 course at MIT

sed可以用-i选项直接改源文件.这里只列了三行,假设stars.csv里有1800行,那么-l参数设300可以把文件拆成 6份.我这样做了,一个个以markdown导出来,发在另一个专栏中,感兴趣的小伙伴可以看看.

1
2
sed -i "s#\(https://github.com/\)\([^,]*\),#- [\2](\1\2)#g" stars.csv 
split -l 300 stars.csv

参考资料

github.com/JeffCarpenter/export-stars
PyGithub/PyGithub