cinemafoundation.in/update.py

41 lines
1.2 KiB
Python
Executable File

#!/usr/bin/python3
from collections import OrderedDict
import ox
api = ox.API('https://indiancine.ma/api/')
doc = api.getDocument(id='DWA')['data']['text']
indent = ' '
indent_s = ' '
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))
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))
section_html = '\n'.join(section_html)
menu_html = '<div id="menu">\n' + indent + (' &middot;\n' + indent).join(menu_html) + '\n'+indent_s+'</div>\n'
menu_html += indent_s + '<a id="link" target="_blank"></a>\n'
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)