cinemafoundation.in/update.py

35 lines
956 B
Python
Raw Normal View History

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']
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'
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)