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'])
def generate_chapter(self, n, plotter, **kwargs): ### tell the plotter to give us an acceptable plot ### plot = plotter.generate_acceptable_plot(**kwargs) ### dump the synopsis, if requested ### if self.synopsis: plot.print_synopsis() sys.exit(0) ### write a story around the plot, then edit it ### story = plotter.plot_to_story(plot) story = edit_story(story, self.introduced, **kwargs) ### dump the story, if requested ### if self.dump: story.dump(sys.stdout) sys.exit(0) ### give the thing a title that hasn't been used yet ### self.chapters[n]['commuted_plots'] = plotter.commuted_plots self.chapters[n]['plot'] = plot self.chapters[n]['title'] = self.pick_title(plot) ### install it in the chapters ### text = story.render() text = proofread(text) self.chapters[n]['text'] = text self.chapters[n]['word_count'] = word_count(text)