forked from hacs/default
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove_publishers.py
66 lines (55 loc) · 1.98 KB
/
remove_publishers.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import json
# Information https://hacs.xyz/docs/publish/remove
REMOVED_PUBLISHERS = [
{
"publisher": "reharmsen",
"link": "https://github.com/hacs/integration/issues/2192",
},
{
"publisher": "fred-oranje",
"link": "https://github.com/hacs/integration/issues/2748",
},
]
CATEGORIES = [
"appdaemon",
"integration",
"netdaemon",
"plugin",
"python_script",
"theme",
]
TO_REMOVE = {category: [] for category in CATEGORIES}
for entry in REMOVED_PUBLISHERS:
for category in CATEGORIES:
with open(category, "r") as cat_file:
content = json.loads(cat_file.read())
for key in content.copy():
if entry["publisher"] in key.lower():
print(f"Found {key} in {category}")
TO_REMOVE[category].append(
{"repository": key, "link": entry["link"]}
)
with open("blacklist", "r") as blacklist_file:
blacklistcontent = json.loads(blacklist_file.read())
with open("removed", "r") as removed_file:
removedcontent = json.loads(removed_file.read())
for category in TO_REMOVE:
if len(TO_REMOVE[category]) != 0:
with open(category, "r") as cat_file:
categorycontent = json.loads(cat_file.read())
for entry in TO_REMOVE[category]:
blacklistcontent.append(entry["repository"])
removedcontent.append(
{**entry, "reason": "Author removed", "removal_type": "removal"}
)
categorycontent.remove(entry["repository"])
with open(category, "w") as cat_file:
cat_file.write(
json.dumps(sorted(categorycontent, key=str.casefold), indent=2)
)
with open("blacklist", "w") as blacklist_file:
blacklist_file.write(
json.dumps(sorted(blacklistcontent, key=str.casefold), indent=2)
)
with open("removed", "w") as removed_file:
removed_file.write(json.dumps(removedcontent, indent=2))