2018-01-11 13:20:40 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
from collections import OrderedDict
|
|
|
|
|
|
|
|
import ox
|
|
|
|
|
|
|
|
api = ox.API('https://indiancine.ma/api/')
|
|
|
|
doc = api.getDocument(id='DWA')['data']['text']
|
|
|
|
|
2018-01-12 10:19:39 +00:00
|
|
|
indent = ' '
|
|
|
|
indent_s = ' '
|
|
|
|
|
2018-01-11 13:20:40 +00:00
|
|
|
section_html = []
|
|
|
|
menu_html = []
|
|
|
|
for section in doc.split('<h1>')[1:]:
|
|
|
|
title = section[:section.index('</h1>')]
|
|
|
|
name = title.lower()
|
|
|
|
html = section[section.index('</h1>')+5:]
|
|
|
|
menu_html.append('<a href="#{}">{}</a>'.format(name, title))
|
2018-01-12 10:19:39 +00:00
|
|
|
html = html.replace('<br><br>', '').replace('<p></p>', '')
|
|
|
|
html = '\n'.join([indent + r for r in html.strip().split('\n')])
|
|
|
|
section_html.append(indent_s + '<div class="section" id="{}">\n{}\n{}</div>'.format(name, html, indent_s))
|
2018-01-11 13:20:40 +00:00
|
|
|
|
|
|
|
section_html = '\n'.join(section_html)
|
2018-01-12 10:19:39 +00:00
|
|
|
menu_html = '<div id="menu">\n' + indent + (' ·\n' + indent).join(menu_html) + '\n'+indent_s+'</div>\n'
|
|
|
|
menu_html += indent_s + '<a id="link" target="_blank"></a>\n'
|
2018-01-11 13:20:40 +00:00
|
|
|
|
|
|
|
with open('index.html') as fd:
|
|
|
|
index = fd.read()
|
|
|
|
|
|
|
|
head = index[:index.index('<div id="menu">')]
|
|
|
|
footer = '''
|
|
|
|
<script src="icf.js"></script>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
'''
|
|
|
|
|
|
|
|
new_index = head + menu_html + section_html + footer
|
|
|
|
|
|
|
|
with open('index.html', 'w') as fd:
|
|
|
|
fd.write(new_index)
|