"""
Minetest Mod HTML Generator Program
"""
#Imports
import json
#Grabs dictionary of mod from master dictionary
def grabMod(modName):
mod = master_dict[modName]
return mod
#Extracts each part from mod dictionary
def extractMod(mod):
name = mod["Name"]
folder = mod["Folder"]
author = mod["Author"]
depends = mod["Depends"]
forum = mod["Forum"]
database = mod["Database"]
gitHub = mod["GitHub"]
categories = mod["Categories"]
#Wrtie HTML code from mod list
def writeHTML():
html_code = [""]
#Prints general beginning HTML
#Note that "style.css" can be used to style the generated page
html_code.append("")
html_code.append("
")
#Outputs Table of Contents
html_code.append("
")
html_code.append("
Table of Contents
")
html_code.append("
")
for modName, mod in sorted(master_dict.items()):
html_code.append("- " + mod["Name"] + " - (" + mod["Folder"] + ")" + "
")
html_code.append("
")
html_code.append("
")
#Ouputs list header
html_code.append("
List of Mods
")
#Prints info for each mod in alphabetical order
for modName, mod in sorted(master_dict.items()):
html_code.append("
" + mod["Name"] + " [" + mod["Folder"] + "]
")
html_code.append("
")
html_code.append("- " + "Folder Name: " + mod["Folder"] + "
")
html_code.append("- " + "Author: " + mod["Author"] + "
")
if mod["Depends"] != "":
html_code.append("- " + "Depends: " + mod["Depends"] + "
")
else:
html_code.append("- " + "Depends: None
")
#Prints values that are links as HTML links
#Forum Topic
if mod["Forum"] != "None":
html_code.append("- " + "Forum Topic: " + "" + mod["Forum"] + "" + "
")
else:
html_code.append("- " + "Forum Topic: None
")
#Mod Database Entry
if mod["Database"] != "None":
html_code.append("- " + "MMDB Entry: " + "" + mod["Database"] + "" + "
")
else:
html_code.append("- " + "MMDB Entry: None
")
#GitHub repo
if mod["GitHub"] != "None":
html_code.append("- " + "GitHub Repo: " + "" + mod["GitHub"] + "" + "
")
else:
html_code.append("- " + "GitHub Repo: None
")
html_code.append("- " + "Categories: " + mod["Categories"] + "
")
html_code.append("
")
html_code.append("")
#Prints general ending HTML code
html_code.append("
")
#Create HTML file
html_file = open("mod_list.html", "w")
#Write to HTML file
html_file.write(str.join("\n", html_code))
#Print HTML
print(str.join("\n", html_code))
#Close HTML file
html_file.close()
#Open data file and get master directory from data file
data_file = "mod_data.txt"
global master_dict
master_dict = {}
master_dict = json.load(open(data_file))
#Call writeHTML function
writeHTML()