-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsync-description.py
executable file
·41 lines (35 loc) · 1.05 KB
/
sync-description.py
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
#!/usr/bin/env python3
import glob
import urllib.request
import json
import os
req = urllib.request.Request(
"https://hub.docker.com/v2/users/login",
data=json.dumps(
{
"username": os.getenv("DOCKERHUB_USERNAME"),
"password": os.getenv("DOCKERHUB_PASSWORD"),
}
).encode(),
headers={"Content-Type": "application/json"},
)
resp = urllib.request.urlopen(req)
token = json.loads(resp.read())["token"]
for readme in glob.glob("*/README.md"):
repo = readme[: -len("/README.md")]
print("Updating description for", repo)
with open(readme) as f:
desc = f.read()
req = urllib.request.Request(
"https://hub.docker.com/v2/repositories/zhusj/" + repo + "/",
data=json.dumps(
{
"full_description": desc,
}
).encode(),
headers={"Content-Type": "application/json", "Authorization": "JWT " + token},
method="PATCH",
)
resp = urllib.request.urlopen(req)
print("Result:", resp.code)
# vim:ai:et:ts=4:sts=4:sw=4: