mirror of
https://github.com/alexhopeoconnor/default.git
synced 2026-10-22 10:42:11 +10:00
Add remove publishers script
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import json
|
||||
|
||||
# Information https://hacs.xyz/docs/publish/remove
|
||||
REMOVED_PUBLISHERS = []
|
||||
|
||||
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))
|
||||
Reference in New Issue
Block a user