import sys
import os

if len(sys.argv) < 3:
	print("Usage: pre_process.py [edition, 2024 or 2025] [web folder path]")
	exit(-1)

def process_edition(year, community):
	with open(os.path.join(sys.argv[2], "index_template.html")) as f:
		index_template = f.read()

	index = index_template \
		.replace("{YEAR}", year) \
		.replace("{COMMUNITY}", community)

	for known_year in ["2025", "2024"]:
		if known_year == year:
			index = index.replace("{" + known_year + "ONLYCOMMENTSTART}", "<!--")
			index = index.replace("{" + known_year + "ONLYCOMMENTEND}", "-->")
			index = index.replace("{NOT" + known_year + "ONLYCOMMENTSTART}", "")
			index = index.replace("{NOT" + known_year + "ONLYCOMMENTEND}", "")
		else:
			index = index.replace("{" + known_year + "ONLYCOMMENTSTART}", "")
			index = index.replace("{" + known_year + "ONLYCOMMENTEND}", "")
			index = index.replace("{NOT" + known_year + "ONLYCOMMENTSTART}", "<!--")
			index = index.replace("{NOT" + known_year + "ONLYCOMMENTEND}", "-->")

	with open(os.path.join(sys.argv[2], "index.html"), "w") as f:
		f.write(index)

if sys.argv[1] == "2024":
	process_edition("2024", "2024lemmycanvasatlas")
elif sys.argv[1] == "2025":
	process_edition("2025", "2025fedicanvasatlas")
else:
	print("Unrecognizeable edition: " + sys.argv[1])
	exit(-1)
