Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Card password conversion
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
苍蓝
Card password conversion
Commits
d8d9cc7c
Commit
d8d9cc7c
authored
Sep 04, 2024
by
苍蓝
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
b6925bd2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
1 deletion
+81
-1
app.ico
app.ico
+0
-0
deckcode.py
deckcode.py
+80
-0
to-pre.txt
to-pre.txt
+1
-1
No files found.
app.ico
0 → 100644
View file @
d8d9cc7c
16.6 KB
deckcode.py
0 → 100644
View file @
d8d9cc7c
import
os
import
urllib.request
from
datetime
import
datetime
,
timedelta
# 设置文件夹和文件路径
folder_path
=
"deck"
formal_file
=
"to-formal.txt"
pre_file
=
"to-pre.txt"
url_formal
=
"https://code.mycard.moe/coccvo/card-password-conversion/-/raw/master/to-formal.txt"
url_pre
=
"https://code.mycard.moe/coccvo/card-password-conversion/-/raw/master/to-pre.txt"
# 检查 deck 文件夹是否存在
if
not
os
.
path
.
exists
(
folder_path
):
print
(
"Error: 请把此文件放到游戏目录中再运行"
)
input
(
"按回车键退出..."
)
exit
(
1
)
# 定义一个函数来下载对照表
def
download_file
(
url
,
filename
):
try
:
urllib
.
request
.
urlretrieve
(
url
,
filename
)
except
Exception
as
e
:
print
(
f
"Error: 下载对照表失败 {e}"
)
input
(
"按回车键退出..."
)
exit
(
1
)
# 检查对照表文件是否存在,以及是否需要更新
def
check_and_update_file
(
filename
,
url
):
if
not
os
.
path
.
exists
(
filename
):
print
(
f
"{filename} 不存在,开始下载..."
)
download_file
(
url
,
filename
)
else
:
file_mod_time
=
datetime
.
fromtimestamp
(
os
.
path
.
getmtime
(
filename
))
current_time
=
datetime
.
now
()
if
(
current_time
-
file_mod_time
)
>
timedelta
(
days
=
1
):
print
(
f
"更新 {filename}..."
)
download_file
(
url
,
filename
)
# 更新对照表文件
check_and_update_file
(
formal_file
,
url_formal
)
check_and_update_file
(
pre_file
,
url_pre
)
# 读取对照表并构建替换规则字典
replacements
=
{}
with
open
(
formal_file
,
'r'
,
encoding
=
'utf-8'
)
as
file
:
for
line
in
file
:
parts
=
line
.
strip
()
.
split
(
'
\t
'
)
if
len
(
parts
)
==
2
:
replacements
[
parts
[
0
]]
=
parts
[
1
]
# 逆向读取第二个对照表
with
open
(
pre_file
,
'r'
,
encoding
=
'utf-8'
)
as
file
:
for
line
in
file
:
parts
=
line
.
strip
()
.
split
(
'
\t
'
)
if
len
(
parts
)
==
2
:
replacements
[
parts
[
1
]]
=
parts
[
0
]
# 遍历deck文件夹中的所有.ydk文件
for
root
,
dirs
,
files
in
os
.
walk
(
folder_path
):
for
file
in
files
:
if
file
.
endswith
(
".ydk"
):
file_path
=
os
.
path
.
join
(
root
,
file
)
with
open
(
file_path
,
'r'
,
encoding
=
'utf-8'
)
as
f
:
original_content
=
f
.
read
()
# 替换文本
new_content
=
original_content
for
old
,
new
in
replacements
.
items
():
new_content
=
new_content
.
replace
(
old
,
new
)
# 仅当内容发生变化时才写回文件
if
new_content
!=
original_content
:
with
open
(
file_path
,
'w'
,
encoding
=
'utf-8'
)
as
f
:
f
.
write
(
new_content
)
print
(
f
"修改并写入卡组: {file_path}"
)
else
:
print
(
f
"卡组无需修改: {file_path}"
)
print
(
"卡组更新完成。"
)
input
(
"按回车键退出..."
)
to-pre.txt
View file @
d8d9cc7c
89604813 100224032
\ No newline at end of file
100224032 89604813
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment