-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.py
More file actions
43 lines (36 loc) · 1.36 KB
/
example.py
File metadata and controls
43 lines (36 loc) · 1.36 KB
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
import requests
import base64
import json
# 上传文件
def upload_file_to_github_drawing_bed():
file_name = "屏幕截图(1).png" #文件名
token = ""
# url = "https://api.github.com/repos/Ike-li/Drawing_Bed/contents/"+file_name # 用户名、库名、路径
url = "https://api.github.com/repos/[user]/[repo]/contents/[path]/"+file_name # 用户名、库名、路径
headers = {"Authorization": "token " + token}
# content = file_base64(file_data)
f = open(r'C:\Users\ASUS_Ike\Pictures\Screenshots\屏幕截图(1).png', 'rb')
fnb64 = base64.b64encode(f.read()).decode('utf-8')
content = fnb64
# print(content)
data = {
"message": "message",
"committer": {
# "name": "Ike-li",
# "email": "sinyercy@163.com"
"name": "[user]",
"email": "user@163.com"
},
"content": content
}
data = json.dumps(data)
req = requests.put(url=url, data=data, headers=headers)
req.encoding = "utf-8"
re_data = json.loads(req.text)
print(re_data)
print(re_data['content']['sha'])
print("https://cdn.jsdelivr.net/gh/Ike-li/Drawing_Bed/pictures"+file_name)
# 在国内默认的down_url可能会无法访问,因此使用CDN访问
if __name__ == '__main__':
# fdata = open_file('bg-dropdown.png')
upload_file_to_github_drawing_bed()