qud-mods/.readme_generator.py

37 lines
1,007 B
Python
Raw Permalink Normal View History

#!/usr/bin/env python
from json import loads
from os import path, sep, scandir
OUT_FILE = "README.md"
TITLE = "Celediel's Cave's of Qud Mods"
STEAM_WORKSHOP = "https://steamcommunity.com/sharedfiles/filedetails/?id="
def main():
manifest = "workshop.json"
doc = f"# {TITLE}\n\n"
for dir in scandir():
found_manifest = dir.path + sep + manifest
if path.exists(found_manifest):
with open(found_manifest) as file:
mod = loads(file.read())
doc += f"## {mod['Title']}\n"
doc += str(
f'<img src="{dir.name}{sep}{mod["ImagePath"]}" '
2024-06-16 20:49:32 -04:00
+ 'alt="mod preview" '
+ 'width="48" height="48" /><br/>\n\n',
)
doc += f"{mod['Description']}\n\n"
doc += "[Link to the Steam Workshop page]"
2023-12-21 13:01:39 -05:00
doc += f"({STEAM_WORKSHOP}{mod['WorkshopId']})\n\n"
2023-12-21 13:01:39 -05:00
with open(OUT_FILE, "w") as file:
file.write(doc)
if __name__ == "__main__":
main()