Skip to content

Commit

Permalink
Create generate_image_json.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Sliverkiss authored Feb 20, 2024
1 parent e185a1d commit 273e032
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/scripts/generate_image_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os
import json

def generate_json():
image_folder = 'test'
json_data = {
"name": "Sakura图标订阅",
"description": "收集一些自己脚本用到的图标",
"icons": []
}

for filename in os.listdir(image_folder):
if filename.endswith(".png"):
image_path = os.path.join(image_folder, filename)
raw_url = f"https://raw.githubusercontent.com/{os.environ['GITHUB_REPOSITORY']}/main/{image_path}"
icon_data = {"name": filename, "url": raw_url}
json_data["icons"].append(icon_data)

# Set the output path relative to the repository root
output_path = os.path.join(os.getcwd(), 'test.icons.json')

with open(output_path, 'w', encoding='utf-8') as json_file:
json.dump(json_data, json_file, ensure_ascii=False, indent=2)

# Save output data to the GITHUB_STATE environment file
with open(os.environ['GITHUB_STATE'], 'a') as state_file:
state_file.write(f"ICONS_JSON_PATH={output_path}\n")

if __name__ == "__main__":
generate_json()

0 comments on commit 273e032

Please sign in to comment.