mirror of
https://github.com/DeaDvey/mathgenerator.git
synced 2025-11-28 06:25:23 +01:00
🤖 made makeReadme.py fully automated
This commit is contained in:
@@ -1,25 +1,51 @@
|
||||
# To use, paste at bottom of mathgen.py code, change line variable and remove all table rows in README.md except for the top 2 and run mathgen.py
|
||||
# NOTE: not anymore. but still leaving this comment in.
|
||||
from mathgenerator.mathgen import *
|
||||
|
||||
wList = getGenList()
|
||||
lines = []
|
||||
with open('mathgenerator/mathgen.py', 'r') as f:
|
||||
lines=f.readlines()
|
||||
|
||||
allRows = []
|
||||
f = open('mathgen.py')
|
||||
lines = f.readlines()
|
||||
line = 720 # This has to be changed depending on which line the first generator appears on
|
||||
line = lines.index('# Funcs_start - DO NOT REMOVE!\n')+1 # get the first line of the functions in mathgen.py
|
||||
for item in wList:
|
||||
myGen = item[2]
|
||||
prob, sol = myGen()
|
||||
# NOTE: renamed 'sol' to 'solu' to make it look nicer
|
||||
prob, solu = myGen()
|
||||
prob = str(prob).rstrip("\n")
|
||||
sol = str(sol).rstrip("\n")
|
||||
solu = str(solu).rstrip("\n")
|
||||
# edge case for matrixMultiplication
|
||||
if item[0] == 46:
|
||||
print(prob)
|
||||
|
||||
prob = prob.replace("[[", "<table><tr><td>")
|
||||
prob = prob.replace("[", "<tr><td>")
|
||||
prob = prob.replace(", ", "</td><td>")
|
||||
prob = prob.replace("]]\n", "</td></tr></table>")
|
||||
prob = prob.replace("]\n", "</td></tr>")
|
||||
print(prob)
|
||||
|
||||
instName = lines[line]
|
||||
def_name = instName[:instName.find('=')].strip()
|
||||
row = [myGen.id, myGen.title, prob, sol, def_name]
|
||||
func_name = instName[:instName.find('=')].strip() # NOTE: renamed 'def_name' to 'func_name' because it suits it more
|
||||
row = [myGen.id, myGen.title, prob, solu, func_name]
|
||||
# print(item[1], func_name)
|
||||
line += 1
|
||||
if line > len(lines):
|
||||
break
|
||||
allRows.append(row)
|
||||
|
||||
g = open('../README.md', "a")
|
||||
for row in allRows:
|
||||
tableLine = "| " + str(row[0]) + " | " + str(row[1]) + " | " + str(row[2]) + " | " + str(row[3]) + " | " + str(row[4]) + " |\n"
|
||||
g.write(tableLine)
|
||||
g.close()
|
||||
with open('README.md', "r") as g:
|
||||
lines = g.readlines()
|
||||
|
||||
line = lines.index('[//]: # list start\n')
|
||||
lines = lines[:line+1]
|
||||
|
||||
for row in allRows:
|
||||
tableLine = "| " + str(row[0]) + " | " + str(row[1]) + " | " + str(row[2]) + " | " + str(row[3]) + " | " + str(row[4]) + " |\n"
|
||||
lines.append(tableLine)
|
||||
|
||||
with open('README.md', "w") as g:
|
||||
g.writelines(lines)
|
||||
|
||||
print("New README.md table generated")
|
||||
|
||||
Reference in New Issue
Block a user