批量删除github仓库笔记

2021-05-30  本文已影响0人  yanhooIT

创建批量删除仓库的token

删除Python脚本如下

from time import sleep
import requests

# 这里将xxxxxxxx替换为生成的token
headers = {
    "Accept": "application/vnd.github.v3+json",
    "Authorization": "token xxxxxxxx",
    "X-OAuth-Scopes": "repo"
}

with open('./repos.txt', 'r', encoding='utf-8') as f:
    data = f.readlines()

url = "https://api.github.com/repos/{}/{}"
urls = []
for line in data:
    name, repo = line.strip().split("/")
    urls.append(url.format(name, repo))

for l in urls:
    requests.delete(url=l, headers=headers)
    sleep(2)

构建要删除的仓库列表文件

username/repo1
username/repo2
username/repo3

开始批量删除

补充:利用正则表达式快速过滤出要删除的仓库列表

上一篇 下一篇

猜你喜欢

热点阅读