Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2023/2/16 23:26
# @Author : Lertoon Wang
# @File : main.py
# @Software: PyCharm
# public package
import os
import docx
# personal package
import funcs
import setting
class ControlTitle:
"""
the class of control title
"""
def __init__(self, factor_dict):
# possible control factors
self.pic_left = factor_dict.get("pic_left")
self.pic_center = factor_dict.get("pic_center")
self.pic_right = factor_dict.get("pic_right")
self.pic_left_animation = factor_dict.get("pic_left_animation")
self.pic_center_animation = factor_dict.get("pic_center_animation")
self.pic_right_animation = factor_dict.get("pic_right_animation")
self.scene = factor_dict.get("scene")
self.music = factor_dict.get("music")
self.sound = factor_dict.get("sound")
def scan(file):
"""
scan the word file in lines and transform in to the nova script
:return:
"""
file.write(setting.headingInfo) # write the heading info into the nova script
file.write(setting.mediaInfo) # write the media info into the nova script
wordFile = docx.Document(setting.docxPath) # open the word file
for para in wordFile.paragraphs: # scan every paragraph
ifControl = para.text.startswith("【") # judge if the paragraph is a control title
if ifControl:
factors = funcs.__sliceFactors(para, setting.GlobalFactorDict) # slice the factors from the control title
controlObject = ControlTitle(factors) # create a control title object
factors_text = ""
for key, value in factors.items():
factors_text += key + "(" + "\'" + value + "\'" + ")\n"
text = "<|\n" + factors_text + "|>\n" # create the control title text
file.write(text) # write the control title text into the nova script
else:
character, dialogue = funcs.__slicePlainText(para)
print(character + ":" + dialogue)
text = character + "::" + dialogue + "\n" # create the plain text
file.write(text) # write the plain text into the nova script
if __name__ == '__main__':
ifExist = os.path.exists(setting.docxPath)
if ifExist:
try:
with open(setting.savePath, "w") as f:
scan(f)
f.close()
except Exception as e:
print(e)
else:
print("word文档不存在, 请检查路径!")