def gen_html(page, command, assets, content, links, previous_page): print('>', command.encode(sys.stdout.encoding, errors='ignore').decode(sys.stdout.encoding).replace('>', '>').replace('<', '<').replace('&', '&')) sys.stdout.flush() images = map(_format_asset, assets) anchors = map(_format_anchor, links) content = map(_rewrite_links, content) content = _rewrite_dialogue(list(content)) navigation = _format_navigation(previous_page) room, alt, img = stories.scratch_banner(page) if room: banner = _format_banner(room) html = _scratch_template.format(command=command, assets='<br/>\n<br/>\n'.join(images), narration='<br/>\n'.join(content), commands=''.join(anchors), banner=banner, alt_text=alt, alt_img='imgtip[{0}]'.format(img), navigation=navigation) elif page == '005982': html = _sbahj_template.format(command=command, assets='<br/>\n<br/>\n'.join(images), narration='<br/>\n'.join(content), commands=''.join(anchors), navigation=navigation) elif page == '006009': html = _cascade_template.format(assets=_format_cascade(), commands=''.join(anchors), banner='../images/header_cascade.gif') elif page == '006715': html = _dota_template.format(command=command, assets='<br/>\n<br/>\n'.join(images), narration='<br/>\n'.join(content), commands=''.join(anchors)) else: html = _html_template.format(command=command, assets='<br/>\n<br/>\n'.join(images), narration='<br/>\n'.join(content), commands=''.join(anchors), navigation=navigation) with open('{0}/{1}/{2}.html'.format(archdir, story, page), 'w') as f: f.write(html)
def get_page(self, page, source): if archive.page_exists(page): definition = archive.page_load(page) else: page_uri = site_prefix + '{0}/{1}.txt'.format(self.story, page) definition = urlopen(page_uri).readall() archive.save_page(page, definition) if page == '006009': return self._get_cascade() command, hash1, hash2, art, narration, next_pages = self._separated_sections(definition.splitlines()) # banner room, alt, img = stories.scratch_banner(page) if room: self._get_asset(site_prefix+'storyfiles/hs2/scratch/'+room) if img: self._get_other(site_prefix+'storyfiles/hs2/scraps/LEtext{0}.gif'.format(img+1)) # main images hidden_nexts = [] for line in art: hidden_nexts.extend(self._get_asset(line)) # inline images for line in narration: for match in re.findall(site_prefix+r'([^\?]*?)"', line): if not 'sweetbroandhellajeff' in match: self._get_asset(site_prefix+match) archive.gen_html(page, command[0], art, narration, next_pages, source) return map(lambda s: (s.strip(), page), next_pages + hidden_nexts)