Since my childhood I am a big fan of mathematics. I always look around the internet to find out challenging problems to solve. In my college days, I found out about Project Euler and I loved to solve them and show others how I did it and finding different methods to do it

I still try to solve them sometimes.

The problem arose when I wanted to showcase my answers in a blog.

I wanted to solve the problem in a new way instead of using php or a jquery. So, being a fan of python, I wrote a python script that reads through bunch of text files and saves the blog in a nice html file.

I saved the redundant lines like header, title, scripts, etc in a text file. Then sweeped through the folder that had my euler solutions and merged the reduntant text files and the solution code to a new html file. It was pretty fun doing it that way.

writer.py


import os,re

with open(r'eulertemplates\1.txt') as t:
	text1 = t.read()
with open(r'eulertemplates\2.txt') as t:
	text2 = t.read()
with open(r'eulertemplates\3.txt') as t:
	text3 = t.read()
with open(r'eulertemplates\4.txt') as t:
	text4 = t.read()
with open(r'eulertemplates\5.txt') as t:
	text5 = t.read()

eulerFolder = r'Eulersolutions'

for file in os.listdir(eulerFolder):
	seeFile = eulerFolder+'\\'+file
	with open(seeFile) as t:
		code = t.read()
	
	num = re.compile(r'^pe(\d\d\d)')
	title = num.search(file).group(1)
	
	pelink = str(int(title))
	
	blog = text1 + title + text2 + title + text3 + pelink + text4 + code + text5
	
	blogFileName = title + '.html' 
	blogFileFolder = r'euler'
	blogLocation = blogFileFolder + '\\' + blogFileName
	
	writer = open(blogLocation,'w')
	writer.write(blog)
	writer.close()