コード例 #1
0
ファイル: models.py プロジェクト: hrichardlee/retellingtime
    def combine_timelines(cls, timelines):
        event_lists = [json.loads(t.events) for t in timelines]

        # find the timeline with the oldest event
        first_timeline = timelines[min(enumerate(event_lists), key=lambda es: es[1][-1])[0]]

        combination = cls(
            orig_titles=json.dumps([t.title for t in timelines]),
            title=' + '.join(t.title for t in timelines),
            url=first_timeline.url,
            events=json.dumps(cls.combine_events(event_lists))
        )
        combination.set_params(htmlprocess.param_defaults({}))
        combination.fewer_than_threshold = all(t.fewer_than_threshold for t in timelines)
        combination.save()
コード例 #2
0
ファイル: models.py プロジェクト: hrichardlee/retellingtime
    def process_wikipedia_page(cls, page_title, refresh=False, p=None):
        """Looks for the wikipedia page with the given title in the database.
        If found, (optionally) refreshes it and returns it. If it is not found, tries
        to parse the wikipedia page. If successful, returns the result. Otherwise
        returns None."""
        page_title = wikipediaprocess.normalize_title(page_title)
        objs = cls.objects.filter(title__iexact=page_title)
        if objs:
            # assume that there is only ever one item with the same title
            timeline = objs[0]
            if refresh and not timeline.banned:
                timeline.get_events()
        else:
            timeline = cls(title=page_title)
            timeline.set_params(htmlprocess.param_defaults(p or {}))
            timeline.get_events()

        if timeline.is_valid:
            return timeline
        else:
            return None