因为使用github作为图床有1G限制(超过1G会有人工审核)所以需要对github仓库容量进行监控

我们可以使用python+tk来做一个GUI

最下方用工具下载链接

准备工具

python GitHub图床

python代码

利用GitHub给出的api制作一个小程序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import requests
import tkinter as tk

# GitHub API 请求头
headers = {
'Accept': 'application/vnd.github.v3+json'
}

def get_repository_size(owner, repo):
url = f'https://api.github.com/repos/{owner}/{repo}'
response = requests.get(url, headers=headers)
if response.status_code == 200:
repository_data = response.json()
size = repository_data['size']
return size
else:
return None

def monitor_repository_size():
owner = entry_owner.get()
repo = entry_repo.get()

size = get_repository_size(owner, repo)
if size is not None:
if size >= 1024 * 1024 * 1024:
size = f"{size / (1024 * 1024 * 1024):.2f} TB"
elif size >= 1024 * 1024:
size = f"{size / (1024 * 1024):.2f} GB"
else:
size = f"{size / 1024:.2f} MB"
label_size.config(text= ("现仓库大小为:") + f" {size}")
else:
label_size.config(text="获取失败请检查用户名或仓库名")

# 创建 GUI 窗口
window = tk.Tk()
window.title("仓库大小监控")
window.geometry("260x170")
window.resizable(width=False, height=False)

# 创建标签和输入框
label_owner = tk.Label(window, text="用户名:")
label_owner.pack()
entry_owner = tk.Entry(window)
entry_owner.pack()

label_repo = tk.Label(window, text="仓库名:")
label_repo.pack()
entry_repo = tk.Entry(window)
entry_repo.pack()

button_monitor = tk.Button(window, text="确定", command=monitor_repository_size)
button_monitor.pack()

label_size = tk.Label(window, text="")
label_size.pack()

label_size1 = tk.Label(window,text="作者:tcmiku")
label_size1.pack()

# 运行 GUI 主循环
window.mainloop()

使用

输入GitHub用户名和作为图床的仓库名即可看见现仓库大小

image-20230627202405671

或者直接使用我制作好的蓝奏云

655941