Last active
May 10, 2016 06:34
-
-
Save fercreek/f6018eee32c3b0e38e84dab54d904fa3 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env python | |
import yaml | |
def generateHtml(msg): | |
return ''' | |
<li> | |
<div class="collapsible-header"> | |
<div class="text--size">{title}</div> | |
</div> | |
<div class="collapsible-body"> | |
<a href="{link}"> | |
{author} | |
</a> | |
</div> | |
</li> | |
'''.format(title=msg['title'], link=msg['link'], author=msg['author']) | |
def encodeMsg(msg): | |
return { | |
'title': msg['title'].encode('utf-8'), | |
'link': msg['link'], | |
'author': msg['author'].encode('utf-8') | |
} | |
def fileFormat(msg): | |
return './files/{volume}/{chapter}/{article}/{number}.pdf'.format( | |
volume=msg['volume'], | |
chapter=msg['chapter'], | |
article=msg['article'], | |
number=msg['number']) | |
def main(): | |
# template = '' | |
template = open('templates.html', 'w') | |
with open("chapters.yaml", 'r') as stream: | |
code = yaml.load(stream) | |
for chap in code['code']['volumes']['chapters']: | |
articles = code['code']['volumes']['chapters'][chap]['articles'] | |
# templaet.append('Inicio de capitulo {}'.format(chap)) | |
template.write('<!-- Inicio de capitulo {} -->'.format(chap)) | |
for a in articles: | |
msg = encodeMsg(a) | |
msg['link'] = fileFormat({ | |
'volume': 'volume1', | |
'chapter': '2', | |
'article': chap, | |
'number': msg['link'] | |
}) | |
html = generateHtml(msg) | |
template.write(html) | |
# template.append(html) | |
# print(html) | |
template.write('<!-- Fin de capitulo {} -->\n'.format(chap)) | |
template.close() | |
main() | |
# Yaml format | |
code: | |
volumes: | |
chapters: | |
1: | |
articles: | |
- {title: "", | |
link: 1, | |
author: ""} | |
2: | |
articles: | |
- {title: "", | |
link: 1, | |
author: ""} | |
- {title: "", | |
link: 1, | |
author: ""} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment