cinemafoundation.in/update.py
2018-01-12 10:23:39 +01:00

35 lines
1,015 B
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']
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))
section_html.append(' <div class="section" id="{}">{}\n </div>'.format(name, html))
section_html = '\n'.join(section_html)
menu_html = '<div id="menu">\n ' + ' &middot;\n '.join(menu_html) + '\n </div>\n'
menu_html += ' <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)