import sys import json cast=[] Scenes = '"Scenes":{' def CheckScene(sceneString): Data = '\t\t\t"lines":[' linesEtc=sceneString while(True): if (linesEtc.find("

") == -1 or linesEtc.find(":") == -1 or linesEtc.find("

") == -1): break temp = linesEtc[linesEtc.find("

"):] temp = temp[:temp.find("

")] noBtag = temp.replace("", "") noBtag = noBtag.replace("", "") noBtag = noBtag[noBtag.find("

")+3:noBtag.find("

")] character = noBtag[:noBtag.find(":")] if not(character in cast): cast.append(character) line = noBtag[noBtag.find(":")+2:] line = line.replace('"', '\\"') if (len(character) == 0) or len(line) == 0: break Data = Data+'\n\t\t\t\t{"Character":"'+character+'","Line":"'+line+'"},' linesEtc=linesEtc[len(noBtag):] Data=Data[:len(Data)-1]+"]\n\t\t\t" return Data file = sys.argv[1] with open(file, "r") as infile: script=infile.read().replace('\n', '\\n') SceneCounter = 1 while (True): if(script.find("[Scene:") == -1): break TestFromSceneOn = script[script.find("[Scene:")+7:] tempEndOfScript= TestFromSceneOn[:TestFromSceneOn.find("[Scene:")] Desc = tempEndOfScript[:tempEndOfScript.find("]")] ToConvLines=tempEndOfScript[tempEndOfScript.find("]"):] Lines = CheckScene(ToConvLines) Scenes = Scenes+'\n\t\t"'+str(SceneCounter)+'":{\n\t\t\t"SceneDescription":"'+Desc+'",\n'+Lines+"}," script = TestFromSceneOn[TestFromSceneOn.find("[Scene:")+7:] SceneCounter = SceneCounter+1 Scenes = Scenes[:len(Scenes)-1]+"}" castStr='"' for member in cast: if(len(member) > 25): continue castStr=castStr+member+'","' castStr = castStr[:len(castStr)-2]+']' with open(file+".json", "w+") as outfile: outfile.write('{"'+file+'":{\n\t"Cast":['+castStr+',\n\t'+Scenes[:len(Scenes)-1]+'\n}\n}\n}') #print(TestFromSceneOn)