def create_graph(filepaths): """ Prepare the `index.html` template. """ graphs = [] if isinstance(filepaths, StringTypes): filepaths = [filepaths] for path in filepaths: contributions = parser.parse_file(path) graph = { "data": gridify_contributions(contributions), "cell_class": _cell_class(contributions.values()), "longest_streak": statistics.longest_streak( [key for key, val in contributions.iteritems() if val > 0]), "current_streak": statistics.current_streak( [key for key, val in contributions.iteritems() if val > 0]), "sum": sum(contributions.itervalues()), } graph["last_date"] = ( [""] + sorted([key for key, v in contributions.iteritems() if v]))[-1] graphs.append(graph) env = Environment(loader=PackageLoader('contributions', 'templates')) env.filters['tooltip'] = tooltip_text env.filters['display_date'] = dateutils.display_date env.filters['elapsed_time'] = dateutils.elapsed_time template = env.get_template("index.html") weekdays = dateutils.weekday_initials() for idx in [0, 2, 4, 6]: weekdays[idx] = "" months = [ cell.date.strftime("%b") for cell in gridify_contributions(contributions)[0] ] months = filter_months(months) return template.render(graphs=graphs, today=dateutils.today(), start=dateutils.start(), weekdays=weekdays, months=months)
def create_graph(filepaths): """ Prepare the `index.html` template. """ graphs = [] if isinstance(filepaths, StringTypes): filepaths = [filepaths] for path in filepaths: contributions = parser.parse_file(path) graph = { "data": gridify_contributions(contributions), "cell_class": _cell_class(contributions.values()), "longest_streak": statistics.longest_streak( [key for key, val in contributions.iteritems() if val > 0] ), "current_streak": statistics.current_streak( [key for key, val in contributions.iteritems() if val > 0] ), "sum": sum(contributions.itervalues()), "repo_name": ntpath.basename(path) } graph["last_date"] = ( [""] + sorted([key for key, v in contributions.iteritems() if v]) )[-1] graphs.append(graph) env = Environment(loader=PackageLoader('contributions', 'templates')) env.filters['tooltip'] = tooltip_text env.filters['display_date'] = dateutils.display_date env.filters['elapsed_time'] = dateutils.elapsed_time template = env.get_template("index.html") weekdays = dateutils.weekday_initials() for idx in [0, 2, 4, 6]: weekdays[idx] = "" months = [ cell.date.strftime("%b") for cell in gridify_contributions(contributions)[0] ] months = filter_months(months) return template.render(graphs=graphs, today=dateutils.today(), start=dateutils.start(), weekdays=weekdays, months=months)
def test_weekday_initials(self): for locale_code, weekdays in WEEKDAY_NAMES.iteritems(): locale.setlocale(locale.LC_ALL, locale_code) self.assertEqual(dateutils.weekday_initials(), weekdays)