Skip to content

Instantly share code, notes, and snippets.

@fr3aker
Created October 25, 2014 22:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fr3aker/f57781e5251af0ccfa1b to your computer and use it in GitHub Desktop.
Save fr3aker/f57781e5251af0ccfa1b to your computer and use it in GitHub Desktop.
very quick and dirty script to fix the new.sql file for Life is Feudal: Your Own server
#!/usr/bin/env python3
f = open("new.sql", "r")
content = f.read()
lines = content.split("\n")
i = 0
# find all BEGIN statements for a CREATE
beginsInLines = list()
while i+1 < len(lines):
if lines[i] == "BEGIN":
beginsInLines.append(i)
i += 1
# find CREATE for BEGIN
for lineNum in beginsInLines:
start = lineNum
lineNum -= 1
while not lines[lineNum].startswith("CREATE"):
lineNum -= 1
lines[lineNum] = "DELIMITER ~~~~\n" + lines[lineNum]
lineNum = start+1
while not lines[lineNum] == "END;":
lineNum += 1
lines[lineNum] = lines[lineNum] + "\n~~~~\nDELIMITER ;"
f = open("fixed_new.sql", "x")
f.write("\n".join(lines))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment