因为今天想整理自己的 github,想把过去 fork 的代码删除掉,只保留自己的,自己手动删除了几个,但发现自己 fork 的工程太多,手动太麻烦,所以,找到 github api 写了如下几行代码
sudo pip PyGithub
#coding=utf-8 from github import Github g = Github("xxxxx", "passwd") my_forks = [] for repo in g.get_user().get_repos(): if repo.fork: my_forks.append(repo) for repo in my_forks: repo.delete()
1 yichinzhu 2017-12-21 16:30:46 +08:00 via Android 所以为什么要 fork 而不是 star |
![]() | 2 yuhanle 2017-12-21 16:35:26 +08:00 手动点赞比心 |
![]() | 5 tofishes 2017-12-21 17:39:36 +08:00 可以让 fork 转 star 么? |
7 lihongjie0209 2017-12-21 22:39:09 +08:00 ``` #coding=utf-8 from github import Github g = Github("xxxxx", "passwd") for repo in g.get_user().get_repos(): if repo.fork: my_forks.append(repo) # 直接删就好了, 不需要中间数组 repo.delete() ``` |
![]() | 8 intohole OP @lihongjie0209 .... 居然纠结这个 |
![]() | 9 corningsun 2017-12-22 11:14:19 +08:00 |
10 lihongjie0209 2017-12-22 11:15:55 +08:00 @intohole #8 看着难受, 要是用中间数组还不如用`yield`, 或者用列表解析式, 或者中 filter, map, 写 Java 考虑设计模式, 写 Python 考虑 PEP8 |