Exemplo n.º 1
0
    def __str__(self):
        """Generates the response string."""
        try:
            self.load()
        except Exception as e:
            logging.error("(STORY) Could not load story!")
            logging.error(e)
            return ("")
        result = ["\n\n"]
        result.append(
            reddit_markdown.link(
                reddit_markdown.bold(
                    reddit_markdown.italics(
                        reddit_markdown.escape(self.get_title()))),
                reddit_markdown.encode_url(self.get_url())) + " by " +
            reddit_markdown.link(
                reddit_markdown.italics(
                    reddit_markdown.escape(self.get_author())),
                reddit_markdown.encode_url(self.get_author_link())))
        result.append("\n\n")
        result.extend(
            reddit_markdown.quote(
                reddit_markdown.escape(self.get_summary())).split("\n"))
        result.append("")
        result.append(reddit_markdown.superscript(self.format_stats()))
        result.append("\n\n" + reddit_markdown.linebreak + "\n\n")

        return "\n".join(result)
Exemplo n.º 2
0
    def __str__(self):
        """Generates the response string."""
        self.load()
        result = ["\n\n"]
        result.append(
            reddit_markdown.link(
                reddit_markdown.bold(
                    reddit_markdown.italics(
                        reddit_markdown.escape(self.get_title()))),
                reddit_markdown.escape(self.get_url())) + " by " +
            reddit_markdown.link(
                reddit_markdown.italics(
                    reddit_markdown.escape(self.get_author())),
                reddit_markdown.escape(self.get_author_link())))
        result.append("\n\n")
        # result.append("\n\n[***%s***](%s) by [*%s*](%s)" %
        #     self.get_title(), self.get_url(),
        #     self.get_author(), self.get_author_link()
        # ))

        result.append("\n\n")
        result.extend(
            reddit_markdown.quote(
                reddit_markdown.escape(self.get_summary())).split("\n"))
        result.append("")
        result.append(reddit_markdown.exponentiate(self.format_stats()))
        # result.append("[" + str(id(self)) + "]: " + self._lnk)
        for name, link in self._lnk:
            result.append("[%s:%s]: %s"%(str(id(self)), name, link))

        result.append("\n\n" + reddit_markdown.linebreak + "\n\n")

        return "\n".join(result)
Exemplo n.º 3
0
    def format_stats(self):
        # Allow the user to opt out of the reformatting
        if "noreformat" in self.context:
            return

        # Separate by lines.
        self.stats = re.sub('(\w+:)', '**|** ' + reddit_markdown.italics(r"\1") + ' ', self.stats)

        # Fix the first word.
        self.stats = self.stats.replace('(**|**', '(')

        # Replace the "dashes" with spaces.
        self.stats = self.stats.replace('- **|**', '**|**')

        # Exponentiate.
        self.stats = reddit_markdown.quote(reddit_markdown.exponentiate(self.stats))
Exemplo n.º 4
0
    def format_stats(self):
        stats = OrderedDict()
        site = self.get_site()
        if site is not None:
            _site = iter(site)
            stats["Site"] = next(_site)

        for k, v in self.get_stats().items():
            stats[self.super_escape(k)] = self.super_escape(v)

        res = []
        for key, value in stats.items():
            res.append(reddit_markdown.italics(key) + ": " + value)

        download = self.get_download()
        if download is not None:
            epub = download[0]
            mobi = download[1]
            res.append(
                "*Download*: [EPUB]({0}) or [MOBI]({1})".format(epub, mobi))
        return (" " + reddit_markdown.bold("|") + " ").join(res)
Exemplo n.º 5
0
    def format_stats(self):
        stats = OrderedDict()
        site = self.get_site()
        self._lnk = []
        if site is not None:
            _site = iter(site)
            site = "[" + next(_site) + "][" + str(id(self)) + ":site]"
            self._lnk.append(("site", next(_site)))
            stats["Site"] = site

        for k, v in self.get_stats().items():
            stats[k] = v

        res = []
        for key, value in stats.items():
            res.append(reddit_markdown.italics(key) + ": " + value)

        download = self.get_download()
        if download is not None:
            res.append("*Download*: [EPUB][%s:epub]"%(str(id(self))))
            self._lnk.append(("epub", download))
        return (" " + reddit_markdown.bold("|") + " ").join(res)