Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wwwanlingxiao
LeetCodeAnimation
Commits
e27e1914
Commit
e27e1914
authored
Apr 16, 2020
by
nettee
Browse files
脚本生成题解目录结构
parent
e73480e9
Changes
2
Hide whitespace changes
Inline
Side-by-side
anima.py
0 → 100755
View file @
e27e1914
#!/usr/bin/env python3
import
re
from
dataclasses
import
dataclass
from
pathlib
import
Path
import
fire
project_dir
=
Path
(
'.'
)
@
dataclass
class
ProblemInfo
:
id
:
int
title
:
str
def
title_slug
(
self
):
title_parts
=
re
.
split
(
r
'\s+'
,
self
.
title
)
return
f
'
{
self
.
id
:
04
d
}
-'
+
'-'
.
join
(
title_parts
)
@
dataclass
class
Article
:
problem
:
ProblemInfo
path
:
Path
@
classmethod
def
create
(
cls
,
problem
:
ProblemInfo
,
path
:
Path
):
article
=
Article
(
problem
,
path
)
article
.
_create_dirs
()
article
.
_create_doc
()
return
article
def
_create_dirs
(
self
):
for
d
in
(
'Animation'
,
'Article'
,
'Code'
):
(
self
.
path
/
d
).
mkdir
()
def
_create_doc
(
self
):
doc_file
=
self
.
path
/
'Article'
/
(
self
.
problem
.
title_slug
()
+
'.md'
)
with
doc_file
.
open
(
'w'
)
as
f
:
pass
def
create_article_r
(
directory
:
Path
,
paths
)
->
None
:
if
isinstance
(
paths
,
str
):
(
directory
/
paths
).
mkdir
()
elif
isinstance
(
paths
,
list
):
for
path
in
paths
:
create_article_r
(
directory
,
path
)
def
create_article
(
problem_id
:
int
,
problem_title
:
str
)
->
None
:
problem
=
ProblemInfo
(
problem_id
,
problem_title
)
article_dir
=
project_dir
/
problem
.
title_slug
()
if
article_dir
.
exists
():
print
(
f
'创建失败,文件夹
{
article_dir
}
已存在'
)
exit
(
1
)
article_dir
.
mkdir
()
article
=
Article
.
create
(
problem
,
article_dir
)
print
(
f
'题解框架创建完毕,位于文件夹
{
article_dir
}
'
)
class
Anima
:
"""
LeetCode Animation Manager
"""
def
new
(
self
,
id
:
str
,
title
:
str
):
create_article
(
id
,
title
)
if
__name__
==
'__main__'
:
anima
=
Anima
()
fire
.
Fire
(
anima
)
requirements.txt
0 → 100644
View file @
e27e1914
fire
\ No newline at end of file
Write
Preview
Supports
Markdown
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