Created
November 27, 2022 17:35
-
-
Save Forest-Dewberry/252a2429f747c45465ee3c017c2422df to your computer and use it in GitHub Desktop.
reformat dominion.games logs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def readfile(filepath): | |
data='' | |
if not (filepath==''): | |
with open(filepath, 'r') as file: | |
data = file.read() | |
return data | |
def writefile(filepath,contents=''): | |
s = contents | |
if s=='': s=input('write the desired file contents here') | |
with open(filepath, 'w') as wf: | |
print(s, file=wf) | |
def appendfile(filepath, contents=''): | |
s = contents | |
if s=='': s=input('write the desired file contents here') | |
currentdata=readfile(filepath) | |
alldata=currentdata + s | |
s=alldata | |
writefile(filepath,s) | |
def bashcmd(bcmd): | |
import subprocess | |
bashCommand = bcmd | |
process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE) | |
output, error = process.communicate() | |
return (output, error) | |
def rdol(filepath): | |
# Names of players are at the top | |
# filepath='WmyMoneyHisEngineBaseSet.txt' | |
lineend='\n' | |
data=readfile(filepath) | |
lines=data.split(lineend) | |
turnstr='Turn' | |
pars=[] | |
pars.append(list()) | |
currentPar=0 | |
for line in lines: | |
pars[currentPar].append(line) | |
if (1+line.find(turnstr)): | |
pars.append(list()) | |
currentPar +=1 | |
writedata='' | |
for par in pars: | |
for i in par: | |
if (i == ''): writedata += '\n' | |
elif (1+i.find(turnstr)): writedata += '\n\n' + i | |
else: writedata=''.join([writedata,i]) | |
writedata+='\n' | |
writefile('reformatted'+filepath,writedata) | |
# data=readfile(filepath) | |
# print(data[0:99]) | |
# findstr=', rated.\n' | |
# lineend='\n' | |
# inames=data.find(findstr) | |
# ifirstname=inames+len(findstr) | |
# print(data[ifirstname:ifirstname+10]) | |
# iendfirstname=data.find(lineend,ifirstname) | |
# irating=data.find(lineend,ifirstname) | |
# rdol('WmyMoneyHisEngineBaseSet.txt') | |
# filepath='WmyMoneyHisEngineBaseSet.txt' | |
# lineend='\n' | |
# data=readfile(filepath) | |
# lines=data.split(lineend) | |
# turnstr='Turn' | |
# pars=[] | |
# pars.append(list()) | |
# currentPar=0 | |
# for line in lines: | |
# pars[currentPar].append(line) | |
# if (1+line.find(turnstr)): | |
# pars.append(list()) | |
# currentPar +=1 | |
# writedata='' | |
# for par in pars: | |
# for i in par: | |
# if (i == ''): writedata += '\n' | |
# elif (1+i.find(turnstr)): writedata += '\n\n' + i | |
# else: writedata=''.join([writedata,i]) | |
# writedata+='\n' | |
# # writefile('reformatted'+filepath,writedata) | |
# data[0:99] | |
# findstr=', rated.\n' | |
# inames=data.find(findstr) | |
# ifirstname=inames+len(findstr) | |
# print(data[ifirstname:ifirstname+10]) | |
# iendfirstname=data.find(lineend,ifirstname) | |
# irating=data[iendfirstname+3] | |
# iendsecondname=data.find(lineend,ifirstname) | |
# irating=data[iendfirstname+3] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment