pyyaml.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env python
  2. # Needs to be installed `pip install pyyaml`
  3. import yaml
  4. import os
  5. browser = "palemoon"
  6. with open('software.yaml') as f:
  7. data = yaml.load(f, Loader=yaml.FullLoader)
  8. beginning = f"""<!DOCTYPE html>
  9. <head>
  10. <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  11. <meta name="viewport" content="width=device-width, initial-scale=1" />
  12. <title>{data["title"]}</title>
  13. <link rel="stylesheet" href="{data["css"]}">
  14. </head>
  15. <body>
  16. <h1>{data["title"]}</h1>
  17. """
  18. items = []
  19. for key, content in data["software"].items():
  20. if "\n" in content:
  21. top = content.split("\n")
  22. item = f"""<h2>{key.replace("_"," ")}</h2>
  23. {top[0]}
  24. <p>{content.replace(top[0],"")}</p>"""
  25. else:
  26. item = f"""<h2>{key.replace("_"," ")}</h2>
  27. <p>{content}</p>"""
  28. items.append(item)
  29. final = '\n'.join(items)
  30. end = """
  31. <hr>
  32. <footer>
  33. <a rel='license' href='http://creativecommons.org/licenses/by-sa/4.0/'><img alt='Creative Commons License' style='border-width:0' width='88' height='31' src='../images/cc-by-sa.png' /></a><br>
  34. Unless otherwise noted, all content on this website is Copyright Zortazert 2021-2022 and is licensed under <a rel='license' href='http://creativecommons.org/licenses/by-sa/4.0/'>CC BY-SA 4.0</a>.
  35. </footer>
  36. </body>
  37. </html>
  38. """
  39. filename = data["title"].lower().replace(" ","_")+".html"
  40. with open(filename,"w") as f:
  41. f.write(beginning+final+end)
  42. os.system(f"{browser} {filename}")