def publish(self): fd, temp_filename = mkstemp(suffix='.md') os.close(fd) with open(temp_filename, 'w') as f: f.write(self.text) f.write("## word counts for this novel\n\n") for n, chapter in enumerate(self.chapters): f.write("Chapter %02d: %s \n" % (n + 1, chapter['word_count'])) f.write("Chapter total: %0.2d \n" % self.total_wc) f.write("Average: %0.2d \n" % self.avg_wc) f.write("Entire Novel: %s \n" % self.novel_wc) log(temp_filename) html_filename = 'temp.html' output_filename = 'Serenity_Starlight.html' os.system( "pandoc --from=markdown --to=html5 --css=marysue.css <%s >%s" % (temp_filename, html_filename)) with open(html_filename, 'r') as f_in: with open(output_filename, 'w') as f_out: for line in f_in: if 'rel="stylesheet"' in line: f_out.write('<style type="text/css">\n') f_out.write(open('marysue.css', 'r').read()) f_out.write('</style>\n') else: f_out.write(line) os.system("firefox %s &" % output_filename)
def publish(self): fd, temp_filename = mkstemp(suffix='.md') os.close(fd) with open(temp_filename, 'w') as f: f.write(self.text) f.write("## word counts for this novel\n\n") for n, chapter in enumerate(self.chapters): f.write("Chapter %02d: %s \n" % (n + 1, chapter['word_count'])) f.write("Chapter total: %0.2d \n" % self.total_wc) f.write("Average: %0.2d \n" % self.avg_wc) f.write("Entire Novel: %s \n" % self.novel_wc) log(temp_filename) html_filename = 'temp.html' output_filename = 'Serenity_Starlight.html' os.system("pandoc --from=markdown --to=html5 --css=marysue.css <%s >%s" % (temp_filename, html_filename)) with open(html_filename, 'r') as f_in: with open(output_filename, 'w') as f_out: for line in f_in: if 'rel="stylesheet"' in line: f_out.write('<style type="text/css">\n') f_out.write(open('marysue.css', 'r').read()) f_out.write('</style>\n') else: f_out.write(line) os.system("firefox %s &" % output_filename)
def trim(self): ### trim the novel to reasonable length ### # Note: this isn't perfect, because every time we cut a chapter, # we make the table of contents shorter too. But, it's usually OK. # The total number of words outside of any chapter is usually around 500. done = False while not done: self.assemble_novel_text() self.novel_wc = word_count(self.text) overrun = self.novel_wc - 50000 could_be_cut = [ (n, c) for (n, c) in enumerate(self.chapters) if c['word_count'] < overrun and c['position'] == 'middle' ] could_be_cut.sort(key=lambda pair: pair[1]['word_count']) if could_be_cut: n, chapter = could_be_cut[0] log('cutting:', n, chapter['title'], chapter['word_count']) self.chapters.remove(chapter) else: done = True self.total_wc = sum( [chapter['word_count'] for chapter in self.chapters]) self.avg_wc = (self.total_wc * 1.0) / (len(self.chapters) * 1.0) self.retitle_chapters() self.assemble_novel_text() self.novel_wc = word_count(self.text) for n, c in enumerate(self.chapters): if c['commuted_plots']: log(n + 1, c['commuted_plots'])
def trim(self): ### trim the novel to reasonable length ### # Note: this isn't perfect, because every time we cut a chapter, # we make the table of contents shorter too. But, it's usually OK. # The total number of words outside of any chapter is usually around 500. done = False while not done: self.assemble_novel_text() self.novel_wc = word_count(self.text) overrun = self.novel_wc - 50000 could_be_cut = [(n, c) for (n, c) in enumerate(self.chapters) if c['word_count'] < overrun and c['position'] == 'middle'] could_be_cut.sort(key=lambda pair: pair[1]['word_count']) if could_be_cut: n, chapter = could_be_cut[0] log('cutting:', n, chapter['title'], chapter['word_count']) self.chapters.remove(chapter) else: done = True self.total_wc = sum([chapter['word_count'] for chapter in self.chapters]) self.avg_wc = (self.total_wc * 1.0) / (len(self.chapters) * 1.0) self.retitle_chapters() self.assemble_novel_text() self.novel_wc = word_count(self.text) for n, c in enumerate(self.chapters): if c['commuted_plots']: log(n+1, c['commuted_plots'])