Пример #1
0
 def generate_rss(self, num_entries):
     entries = sorted(self.afp_entries.values(),
                      key=lambda e: (e.publish_date, e.name),
                      reverse=True)
     template = self.j2_env.get_template("rss.tpl")
     self.write_file("rss.xml", template,
                     {'entries': entries[:num_entries]})
     terminal.success("Generated rss.xml")
Пример #2
0
 def generate_status(self, build_data):
     template = self.j2_env.get_template("status.tpl")
     self.write_file(
         "status.html", template, {
             'entries':
             [self.afp_entries[e] for e in sorted(self.afp_entries)],
             'build_data': build_data
         })
     terminal.success("Generated status.html")
Пример #3
0
 def generate_index(self):
     data = {'is_devel': self.options.is_devel}
     by_year = groupby(sorted(self.afp_entries.values(),
                              key=lambda e: (e.publish_date, e.name),
                              reverse=True),
                       key=lambda e: e.publish_date.year)
     data['by_year'] = [(year, list(entries)) for year, entries in by_year]
     template = self.j2_env.get_template("index.tpl")
     self.write_file("index.html", template, data)
     terminal.success("Generated index.html")
Пример #4
0
 def generate_entries(self):
     counter = 0
     template = self.j2_env.get_template("entry.tpl")
     for name, entry in self.afp_entries.items():
         self.write_file(os.path.join("entries", name + ".html"), template,
                         {
                             'entry': entry,
                             'is_devel': self.options.is_devel
                         })
         counter += 1
     for name, entry in self.afp_entries.no_index.items():
         self.write_file(os.path.join("entries", name + ".html"), template,
                         {
                             'entry': entry,
                             'is_devel': self.options.is_devel
                         })
         counter += 1
     terminal.success(
         "Generated html files for {:d} entries".format(counter))
Пример #5
0
 def generate_statistics(self):
     #TODO: simplify with itertools
     # Count loc and articles per year
     articles_years = dict()
     loc_years = dict()
     for article in self.afp_entries.values():
         try:
             articles_years[article.publish_date.year] += 1
             loc_years[article.publish_date.year] += article.loc
         except KeyError:
             articles_years[article.publish_date.year] = 1
             loc_years[article.publish_date.year] = article.loc
     # Count new authors per year
     author_years = dict()
     for author in self.afp_entries.authors.values():
         first_year = min([e.publish_date.year for e in author.articles])
         try:
             author_years[first_year] += 1
         except KeyError:
             author_years[first_year] = 1
     # Build cumulative values
     author_years_cumulative = author_years.copy()
     for y in sorted(articles_years)[1:]:
         articles_years[y] += articles_years[y - 1]
         loc_years[y] += loc_years[y - 1]
         author_years_cumulative[y] += author_years_cumulative[y - 1]
     data = {'entries': self.afp_entries}
     data['num_lemmas'] = sum([a.lemmas for a in self.afp_entries.values()])
     data['num_loc'] = sum([a.loc for a in self.afp_entries.values()])
     data['years'] = sorted(articles_years)
     data['articles_year'] = [
         articles_years[y] for y in sorted(articles_years)
     ]
     data['loc_years'] = [
         round(loc_years[y], -2) for y in sorted(loc_years)
     ]
     data['author_years'] = [author_years[y] for y in sorted(author_years)]
     data['author_years_cumulative'] = [
         author_years_cumulative[y] for y in sorted(author_years_cumulative)
     ]
     # Find 10 most imported entries, entries with the same number of
     # imports share one place.
     most_used = sorted([a for a in self.afp_entries.values()],
                        key=lambda x: (-len(x.used), x.name))
     # Show more than 10 articles but not more than necessary
     i = 0
     while i < 10 or len(most_used[i].used) == len(most_used[i + 1].used):
         i += 1
     # Groupby iterators trigger some obscure bug in jinja2
     # https://github.com/pallets/jinja/issues/555
     # So don't use groupby iterator directly and convert to list of lists
     data['most_used'] = [(len_used, list(articles)) for (
         len_used,
         articles) in groupby(most_used[:i + 1], key=lambda x: len(x.used))]
     data['articles_by_time'] = sorted(self.afp_entries.values(),
                                       key=lambda x: x.publish_date)
     data['articles_per_year'] = [
         (year, list(articles))
         for (year, articles) in groupby(data['articles_by_time'],
                                         key=lambda x: x.publish_date.year)
     ]
     template = self.j2_env.get_template("statistics.tpl")
     self.write_file("statistics.html", template, data)
     terminal.success("Generated statistics.html")
Пример #6
0
 def generate_download(self):
     template = self.j2_env.get_template("download.tpl")
     self.write_file("download.html", template,
                     {'is_devel': self.options.is_devel})
     terminal.success("Generated download.html")
Пример #7
0
 def generate_topics(self):
     tree = collect_topics(self.entries, self.options.metadata_dir)
     template = self.j2_env.get_template("topics.tpl")
     self.write_file("topics.html", template, {'tree': tree})
     terminal.success("Generated topics.html")
Пример #8
0
 def generate_standard(self, filename, template_name):
     template = self.j2_env.get_template(template_name)
     self.write_file(filename, template, {})
     terminal.success("Generated {}".format(filename))