1 Star 0 Fork 0

BulletYuan / python-text2console.log

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
PINK_extance.py 1.44 KB
一键复制 编辑 原始数据 按行查看 历史
#-*- coding:utf-8 -*-
import re
f=open("PINK.txt","r")
source=""
try:
while (1):
line= f.readline()
if not line:
break
source+=line
finally:
f.close()
REGEX={
"head":"<font[^>]*>",
"attr":"color=\"([^\"]+)\"",
"foot":"<[^>]font>",
"all":"<[^>]*>"
}
colorArr,resultArr=[],[]
for obj in re.findall(REGEX["head"],source, re.M|re.I):
colorArr.append(re.sub("\=",":",re.sub("\"","",re.search(REGEX["attr"],obj).group()))+";")
textArr=re.sub(REGEX["all"],"",re.sub(REGEX["head"],"",re.sub(REGEX["foot"],",",source))).split(',')
textArr.pop()
row=50
cID=0
resultText=""
for i in range(len(textArr)):
if cID<row:
cID+=len(textArr[i])
resultText+="%c"+textArr[i]
else:
resultArr.append(resultText)
resultText=""
cID=0
cID+=len(textArr[i])
resultText+="%c"+textArr[i]
print colorArr
print textArr
print resultArr
f=open("PINK_res.txt","w")
res="console.log(\""
# sId=0
# for i in range(len(resultArr)):
# if resultArr[i]:
# res="console.log(\""+resultArr[i]+"\""
# for c in range(sId,(sId+resultArr[i].count("%"))):
# res+=",\""+colorArr[c]+"\""
# res+=");"
# sId+=resultArr[i].count("%")
# f.write(res)
for i in range(len(resultArr)):
if resultArr[i]:
res+=resultArr[i]+"\\n"
res+="\""
for c in range(len(colorArr)):
res += ",\"" + colorArr[c] + "\""
res += ");"
f.write(res)
f.close()
Python
1
https://gitee.com/bulletyuan/python-text2console.log.git
git@gitee.com:bulletyuan/python-text2console.log.git
bulletyuan
python-text2console.log
python-text2console.log
master

搜索帮助