Skip to content

Commit

Permalink
同步代码
Browse files Browse the repository at this point in the history
  • Loading branch information
DowneyRem committed Sep 7, 2022
1 parent 9dca5eb commit ea4a5d5
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 102 deletions.
10 changes: 10 additions & 0 deletions TelegramBot/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.idea
__pycache__
.pytest_cache
/Novels
/Photos
/test
/ceui
/ceshi
*.zip

141 changes: 88 additions & 53 deletions TelegramBot/FileOperate.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,48 +169,66 @@ def openText(path) -> str:
@openFileCheck
def openDocx(path) -> str:
text = ""
for para in Document(path).paragraphs:
# print(para.paragraph_format.first_line_indent.pt)
if para.style.name == "Normal Indent": # 正文缩进
text += f"  {para.text}\n"
elif para.paragraph_format.first_line_indent.pt >= 15:
text += f"  {para.text}\n"
else:
text += f"{para.text}\n"
try:
docx = Document(path)
except IOError as e:
logging.error(e)
else:
for para in docx.paragraphs:
# print(para.paragraph_format.first_line_indent.pt)
if para.style.name == "Normal Indent": # 正文缩进
text += f"  {para.text}\n"
elif para.paragraph_format.first_line_indent.pt >= 15:
text += f"  {para.text}\n"
else:
text += f"{para.text}\n"
return text


@openFileCheck
def openDoc(path) -> str:
text = ""
word = DispatchEx('Word.Application') # 独立进程
word.Visible = 0 # 0为后台运行
word.DisplayAlerts = 0 # 不显示,不警告
docx = word.Documents.Open(path)
text = docx.Content.Text.replace("\r\r", "\n")

if docx.Paragraphs.CharacterUnitFirstLineIndent == 2: # 首行缩进转空格
texts = ["", ] + text.split()
text = "\n  ".join(texts).strip("\n")

# print(len(text), text, sep="\n")
docx.Close(True)
word.Quit()
return text
try:
docx = word.Documents.Open(path)
except IOError as e:
logging.error(e)
else:
text = docx.Content.Text.replace("\r\r", "\n")
if docx.Paragraphs.CharacterUnitFirstLineIndent == 2: # 首行缩进转空格
texts = ["", ] + text.split()
text = "\n  ".join(texts).strip("\n")
# print(len(text), text, sep="\n")
docx.Close(True)
finally:
word.Quit()
return text


@openFileCheck
def openJson(path) -> any:
with open(path, "rb") as f:
return json.load(f)

try:
with open(path, "rb") as f:
data = json.load(f)
except IOError as e:
logging.error(e)
else:
return data


@openFileCheck
def openExcel(path): # 打开软件手动操作
excel = DispatchEx('Excel.Application') # 独立进程
excel.Visible = 1 # 0为后台运行
excel.DisplayAlerts = 0 # 不显示,不警告
excel.Workbooks.Open(path) # 打开文档
print("打开Excel……")
try:
excel.Workbooks.Open(path) # 打开文档
print("打开Excel……")
except IOError as e:
logging.error(e)


@saveFileCheck
Expand All @@ -219,30 +237,32 @@ def saveDocx(path, text):
word.Visible = 0 # 0为后台运行
word.DisplayAlerts = 0 # 不显示,不警告
template = "D:\\Users\\Administrator\\Documents\\自定义 Office 模板\\小说.dotm"
docx = word.Documents.Add(template) # 创建新的word文档

s = word.Selection
s.FormatText = text # 写入文本
docx.Application.Run("小说排版") # 运行宏

docx.SaveAs2(path, 16) # 保存文档并退出word
name = os.path.basename(path)
print(f"已保存:【{name}】")
docx.Close(True)
word.Quit()
try:
docx = word.Documents.Add(template) # 创建新的word文档
except IOError as e:
logging.error(e)
else:
s = word.Selection
s.FormatText = text # 写入文本
docx.Application.Run("小说排版") # 运行宏
docx.SaveAs2(path, 16) # 保存文档,退出word
logging.info(f"已保存为:{path}")
docx.Close(True)
finally:
word.Quit()


@saveFileCheck
def saveText(path, text):
name = os.path.basename(path)
if not path.endswith(".txt"):
path += ".txt"
try:
with open(path, "w", encoding="UTF8") as f:
f.write(text)
# print(f"已保存:【{name}】")
except IOError:
print(f"保存失败:【{name}】")
logging.error(f"保存失败:{path}")
else:
logging.debug(f"已保存为:{path}")


def saveTxt(path, text):
Expand All @@ -257,28 +277,39 @@ def saveTextDesktop(name, text):

@saveFileCheck
def saveCsv(path, text):
name = os.path.basename(path)
if not path.endswith(".csv"):
path += ".csv"
try:
with open(path, "w", encoding="UTF-8-sig") as f:
f.write(text)
# print(f"已保存为:【{name}】")
except IOError:
print(f"保存失败:【{name}】")

logging.error(f"保存失败:{path}")
else:
logging.info(f"已保存为:{path}")


@saveFileCheck
def saveJson(path, data):
if not path.endswith(".json"):
path = f"{path}.json"
with open(path, 'w', encoding="UTF8") as f:
json.dump(data, f)

try:
with open(path, 'w', encoding="UTF8") as f:
json.dump(data, f)
except IOError:
logging.error(f"保存失败:{path}")
else:
logging.info(f"已保存为:{path}")


@timer
def zipFile(path, password="", delete=0, dir="") -> str:
# 使用 pyzipper ,可用aes256加密,压缩传入的文件或文件夹
# parm delete 不为0时,压缩后删除源文件
# dir 检测 dir 是否在 path 内;修复 PixivSeries 的 TranslateAsZip 压入未翻译文件
"""使用 pyzipper ,可用aes256加密,压缩传入的文件或文件夹
Args:
path: path 待压缩的文件/文件夹路径
password: password 密码
delete: 不为0时,压缩后删除源文件
dir: 检测 dir 是否在 path 内,以修复 PixivSeries 的 TranslateAsZip 压入未翻译文件的bug
"""

def zipSingleFile(path, zippath, password):
if password:
Expand Down Expand Up @@ -336,12 +367,16 @@ def zipFolder(path, zippath, password):

# @timethis
def unzipFile(path, password="", mode=0, delete=0) -> str:
# 使用 pyzipper 可解压加密的zip文件(ase256 与 ZipCrypto),前者会快得多
# 智能解压:path传入zip路径解压zip,传入文件夹则解压其路径下的zip
# 智能解压:zip内无文件夹则会新建以zip文件名为名的文件夹,zip只有单文件不新建文件夹
# mode=1 ,解压zip内部的zip文件
# delete=1 ,解压后删除zip源文件;同时mode=1,解压后会删除所有zip
# 软件压缩设置:勾选zip使用Unicode文件名,避免解压后文件名乱码
"""使用 pyzipper 可解压加密的zip文件(ase256 与 ZipCrypto),前者会快得多
智能解压:path传入zip路径解压zip,传入文件夹则解压其路径下的zip
智能解压:zip内无文件夹,则会新建以zip文件名为名的文件夹,zip只有单文件不新建文件夹
常规软件压缩设置:勾选zip使用Unicode文件名,避免解压后文件名乱码
Args:
path: path 待解压的zip文件/含有zip文件的文件夹路径
password: password 密码
mode: mode=1 解压zip内部的zip文件
delete: delete=1 解压后删除zip源文件;同时 mode=1 解压后会删除所有zip
"""

if os.path.isdir(path):
ziplist = findFile(path, ".zip")
Expand Down
1 change: 1 addition & 0 deletions TelegramBot/MakeTags.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ def main():


if True: # 初始化
# remakeJsons()
makeRaceDict()
main()

Expand Down
18 changes: 10 additions & 8 deletions TelegramBot/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
python-telegram-bot >= 13.4
pixivpy
python-telegram-bot >= 13.4
pixivpy >= 3.7.0
pygtrans >= 1.4.0
opencc
numpy
pyzipper # use pyzipper to encrypt zip in AESZipFile
webdav4
opencc >= 1.1.1
numpy >= 1.22.1
pyzipper >= 0.3.6
webdav4 >= 0.9.5

# dispensable packages, todo in the future
# pixivpy_async
# aiohttp_socks

# dispensable packages
# dispensable packages, only used on Windows
# python-docx
# docx-hitalent # use docx-hitalent instead of python-docx on python 310
# pywin32
# pywin32
81 changes: 40 additions & 41 deletions TelegramBot/tags.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"en": "en",
"en2": "English"
},
"zh": {
"zh": {
"en": "zh",
"en2": "Chinese",
"zh": "中文"
Expand Down Expand Up @@ -51,46 +51,45 @@
"SFW": {
"en": "SFW"
},
"R18": {
"en": "R18",
"en2": "R-18",
"en3": "NSFW"
},
"R18G":{
"en": "R18G",
"en2": "R18-G",
"en3": "R-18G"
},
"Furry": {
"en": "furry",
"zh_cn": "兽人",
"zh_tw": "獸人",
"ja_han": "獣人",
"ja_hira": "じゅうじん",
"ja_roma": "kemono",
"ja_hiragana": "けもの",
"ja_katakana": "ケモノ",
"ja1": "オスケモ",
"ja2": "メスケモ"
},

"Chibi Furry": {
"ja1": "ケモロリ",
"ja2": "ケモショタ",
"ja3": "チビケモ",
"zh": "兽人正太",
"zh2": "兽太"
},
"R18": {
"en": "R18",
"en2": "R-18",
"en3": "NSFW"
},
"R18G": {
"en": "R18G",
"en2": "R18-G",
"en3": "R-18G"
},
"Furry": {
"en": "furry",
"zh_cn": "兽人",
"zh_tw": "獸人",
"ja_han": "獣人",
"ja_hira": "じゅうじん",
"ja_roma": "kemono",
"ja_hiragana": "けもの",
"ja_katakana": "ケモノ",
"ja1": "オスケモ",
"ja2": "メスケモ"
},
"Chibi Furry": {
"ja1": "ケモロリ",
"ja2": "ケモショタ",
"ja3": "チビケモ",
"zh": "兽人正太",
"zh2": "兽太"
},
"Gay": {
"en": "Gay",
"zh": "BL"
},
"Gay furry": {
"en": "Gay Furry",
"ja1": "ケモホモ",
"ja2": "ホモケモ",
"zh": "兽人同性"
},
"Gay furry": {
"en": "Gay Furry",
"ja1": "ケモホモ",
"ja2": "ホモケモ",
"zh": "兽人同性"
},
"Lesbian": {
"en": "Lesbian",
"zh": "GL"
Expand Down Expand Up @@ -339,7 +338,7 @@
},
"Group": {
"en": "Group",
"en1": "3p",
"en1": "3p",
"en2": "np",
"zh": "群交",
"zh2": "群p",
Expand Down Expand Up @@ -426,7 +425,7 @@
"en2": "GainingWeight",
"zh": "育肥",
"zh1": "肥满化",
"ja-kanji": "肥満化"
"ja-kanji": "肥満化"
},
"BattleDamage": {
"en": "BattleDamage",
Expand Down Expand Up @@ -546,11 +545,11 @@
"zh": "雄妊娠",
"zh2": "雄性妊娠"
},
"GutTorture": {
"GutTorture": {
"en": "GutTorture",
"zh": "虐腹"
},
"R18G CBT": {
"R18G CBT": {
"en": "CBT",
"zh": "虐屌"
},
Expand Down

0 comments on commit ea4a5d5

Please sign in to comment.