Dnomd343
2 years ago
2 changed files with 42 additions and 22 deletions
@ -0,0 +1,22 @@ |
|||||
|
#!/usr/bin/env python3 |
||||
|
# -*- coding: utf-8 -*- |
||||
|
|
||||
|
import os |
||||
|
import json |
||||
|
|
||||
|
rootPath = os.path.join( |
||||
|
os.path.dirname(os.path.realpath(__file__)), '../../' |
||||
|
) |
||||
|
dataPath = os.path.join(rootPath, './release/') |
||||
|
metadataFile = os.path.join(rootPath, './assets/metadata.json') |
||||
|
|
||||
|
|
||||
|
def loadData(jsonName: str) -> dict: |
||||
|
content = json.loads(open( |
||||
|
os.path.join(dataPath, '%s.json' % jsonName) |
||||
|
).read()) |
||||
|
metadata = json.loads(open(metadataFile).read()) |
||||
|
return { |
||||
|
'metadata': metadata, |
||||
|
'content': content, |
||||
|
} |
@ -1,33 +1,31 @@ |
|||||
#!/usr/bin/env python3 |
#!/usr/bin/env python3 |
||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||
|
|
||||
import os |
from common import loadData |
||||
import json |
|
||||
|
|
||||
rootPath = os.path.join( |
|
||||
os.path.dirname(os.path.realpath(__file__)), '../../' |
|
||||
) |
|
||||
dataPath = os.path.join(rootPath, './release/') |
|
||||
metadataFile = os.path.join(rootPath, './assets/metadata.json') |
|
||||
|
|
||||
|
|
||||
def loadData(jsonName: str) -> dict: |
def formatMetadata(metadata: dict) -> str: |
||||
content = json.loads(open( |
return '%s\n\n作者:%s\n\n\n%s' % ( |
||||
os.path.join(dataPath, '%s.json' % jsonName) |
metadata['name'], |
||||
).read()) |
metadata['author'], |
||||
metadata = json.loads(open(metadataFile).read()) |
'\n\n'.join(metadata['desc']), |
||||
return { |
) |
||||
'metadata': metadata, |
|
||||
'content': content, |
|
||||
} |
|
||||
|
|
||||
|
|
||||
def releaseChapter(caption: str, content: list) -> str: |
def formatChapter(caption: str, content: list) -> str: |
||||
return '\n\n'.join([caption] + content) |
return '\n\n'.join([caption] + content) |
||||
|
|
||||
|
|
||||
|
def txtRelease(metadata: dict, content: dict) -> str: |
||||
|
result = [formatMetadata(metadata)] |
||||
|
for (title, chapter) in content.items(): |
||||
|
result.append( |
||||
|
formatChapter(title, chapter) |
||||
|
) |
||||
|
return '\n\n\n'.join(result) |
||||
|
|
||||
|
|
||||
data = loadData('rc-4') |
data = loadData('rc-4') |
||||
c = data['content'] |
print( |
||||
for (c, dat) in c.items(): |
txtRelease(data['metadata'], data['content']) |
||||
print(releaseChapter(c, dat)) |
) |
||||
break |
|
||||
|
Loading…
Reference in new issue