Created
December 14, 2018 00:27
-
-
Save willwangcc/01f63bfaca2bfa32eb5288053235a7de to your computer and use it in GitHub Desktop.
#tool #小工具 #学英语
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
src -> markdown | |
""" | |
script_path = "/Users/wangzhixiang/Desktop/Modern.Family.S09E04.srt" | |
name = script_path.split("/")[-1].strip(".srt") | |
print(name) | |
with open(script_path, encoding='utf-8') as f: | |
read_data = f.read() | |
block = read_data.split("\n\n") | |
# print(block[11]) # | |
""" | |
Output: | |
23 | |
00:00:01,530 --> 00:00:03,740 | |
真想知道曼尼现在在做什么 | |
I wonder what Manny's doing right now. | |
""" | |
markdown = "# " + name + "\n" | |
markdown += """ | |
| Number | Timeline | Chinese | English | | |
| :-------- | :---------: | :---------: | :---------: | | |
""" | |
lines = block[11:] | |
for line in lines: | |
group = line.split("\n") | |
if len(group) != 4: continue | |
index, timeline, chinese, english = line.split("\n") | |
markdown += "|" + index + "|" + timeline + "|" + chinese + "|" + english + "|" + "\n" | |
markdown += "\n" | |
authors = block[2:7] | |
for i in authors: | |
author = i.split("}")[-1] | |
markdown += "* " + author + "\n" | |
output_file_path = "/Users/wangzhixiang/Desktop/" + name + ".md" | |
with open(output_file_path, mode="w", encoding="utf-8") as f2: | |
f2.write(markdown) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment