示例#1
0
    def import_posts(self, zipfile, names):
        """Import all posts."""
        out_folder = 'posts'
        providers = micawber.bootstrap_basic()
        for name in names:
            with zipfile.open(name, 'r') as post_f:
                data = json.load(post_f)
                title = data['title']

                slug = utils.slugify(title)

                if not slug:  # should never happen
                    LOGGER.error("Error converting post:", title)
                    return

                description = ''
                post_date = dateutil.parser.parse(data["published"])
                content = data["object"]["content"]

                for obj in data["object"].get("attachments", []):
                    content += '\n<div> {} </div>\n'.format(micawber.parse_text(obj["url"], providers))

                tags = []
                self.write_metadata(os.path.join(self.output_folder, out_folder, slug + '.meta'), title, slug, post_date, description, tags)
                self.write_content(
                    os.path.join(self.output_folder, out_folder, slug + '.html'),
                    content)
示例#2
0
    def import_posts(self, zipfile, names):
        """Import all posts."""
        out_folder = 'posts'
        providers = micawber.bootstrap_basic()
        for name in names:
            with zipfile.open(name, 'r') as post_f:
                data = json.load(post_f)
                title = data['title']

                slug = utils.slugify(title)

                if not slug:  # should never happen
                    LOGGER.error("Error converting post:", title)
                    return

                description = ''
                post_date = dateutil.parser.parse(data["published"])
                content = data["object"]["content"]

                for obj in data["object"].get("attachments", []):
                    content += '\n<div> {} </div>\n'.format(
                        micawber.parse_text(obj["url"], providers))

                tags = []
                self.write_metadata(
                    os.path.join(self.output_folder, out_folder,
                                 slug + '.meta'), title, slug, post_date,
                    description, tags)
                self.write_content(
                    os.path.join(self.output_folder, out_folder,
                                 slug + '.html'), content)
示例#3
0
    def run(self):
        if micawber is None:
            msg = req_missing(['micawber'], 'use the media directive', optional=True)
            return [nodes.raw('', '<div class="text-error">{0}</div>'.format(msg), format='html')]

        providers = micawber.bootstrap_basic()
        return [nodes.raw('', micawber.parse_text(" ".join(self.arguments), providers), format='html')]
示例#4
0
 def run(self):
     if micawber is None:
         msg = "To use the embed directive, install micawber first."
         return [nodes.raw('', '<div class="text-error">{0}</div>'.format(msg), format='html')]
     url = " ".join(self.arguments)
     html = micawber.parse_text(url, self.get_providers())
     return [nodes.raw('', html, format='html')]
示例#5
0
def _gen_media_embed(url, *q, **kw):
    if micawber is None:
        msg = req_missing(['micawber'],
                          'use the media directive',
                          optional=True)
        return '<div class="text-error">{0}</div>'.format(msg)
    providers = micawber.bootstrap_basic()
    return micawber.parse_text(url, providers)
示例#6
0
文件: media.py 项目: davidak/nikola
    def run(self):
        """Run media directive."""
        if micawber is None:
            msg = req_missing(['micawber'], 'use the media directive', optional=True)
            return [nodes.raw('', '<div class="text-error">{0}</div>'.format(msg), format='html')]

        providers = micawber.bootstrap_basic()
        return [nodes.raw('', micawber.parse_text(" ".join(self.arguments), providers), format='html')]
示例#7
0
 def run(self):
     if micawber is None:
         raise Exception("To use the media directive you need to install "
                         "the micawber module.")
     providers = micawber.bootstrap_basic()
     return [
         nodes.raw('',
                   micawber.parse_text(" ".join(self.arguments), providers),
                   format='html')
     ]
示例#8
0
    def run(self):
        if micawber is None:
            msg = (
                "To use the media directive you need to install "
                "the micawber module."
            )
            utils.logger.WARN(msg)
            return [nodes.raw('', '<div class="text-error">{0}</div>'.format(msg), format='html')]

        providers = micawber.bootstrap_basic()
        return [nodes.raw('', micawber.parse_text(" ".join(self.arguments), providers), format='html')]
示例#9
0
文件: media.py 项目: ralsina/waliki
    def run(self):
        if micawber is None:
            msg = "To use the media directive, isntall micawber first."
            return [nodes.raw('', '<div class="text-error">{0}</div>'.format(msg), format='html')]

        url = " ".join(self.arguments)
        providers = micawber.bootstrap_basic()
        data = providers.request(url)
        html = '<h3>{}</h3>{}'.format(
            data['title'],
            micawber.parse_text(url, providers)
        )
        return [nodes.raw('', html, format='html')]
示例#10
0
文件: media.py 项目: ralsina/nikola
    def run(self):
        if micawber is None:
            msg = ("Error: "
                   "To use the media directive you need to install "
                   "the micawber module.")
            utils.show_msg(msg)
            return [
                nodes.raw('',
                          '<div class="text-error">{0}</div>'.format(msg),
                          format='html')
            ]

        providers = micawber.bootstrap_basic()
        return [
            nodes.raw('',
                      micawber.parse_text(" ".join(self.arguments), providers),
                      format='html')
        ]
示例#11
0
 def get_entry_feature(self):
     """
     If there is a video_url we want to include that as a feature, otherwise
     we fall through to the thumbnail
     """
     if self.video_url:
         """
         Ensure that the video is from a site that supports oembed
         """
         if any(v in self.video_url for v in settings.ALLOWED_OMEMBED_SITES):
             """
             Extracting the oembed data using https://github.com/coleifer/micawber
             """
             providers = micawber.bootstrap_basic()
             entry_oembed = micawber.parse_text(self.video_url, providers)
             """ Ensure https, less site warnings the better """
             return string.replace(entry_oembed, 'http://', 'https://')
     if self.thumbnail:
         return '<img src="%s" alt=""/>' % self.get_image_src()
示例#12
0
def md2html(article):
    # Markdown拡張
    exts = [
        'markdown.extensions.extra', 'markdown.extensions.codehilite',
        'markdown.extensions.tables', 'markdown.extensions.toc'
    ]
    content = article[3]
    # Markdownに使われる[xxx](http://xxx.xxx)とHTMLタグの中のURLを除外する
    pattern = re.compile(
        r'''(?<!\]\(|.>|=")https?://[\w/:%#\$&\?~\.=\+\-@]+(?!\)|<|">)''',
        re.S | re.M)
    urls = list(set(re.findall(pattern, content)))
    # urlをリッチコンテンツに変換するparser
    providers = micawber.bootstrap_basic()
    for url in urls:
        # urlをリッチurlに変更(youtubeなどの動画が表示される)
        rich_url = micawber.parse_text(url, providers)
        content = content.replace(url, rich_url)
    content = md.markdown(content, extensions=exts)
    return article[:3] + (content, )
示例#13
0
文件: media.py 项目: andredias/nikola
def _gen_media_embed(url, *q, **kw):
    if micawber is None:
        msg = req_missing(['micawber'], 'use the media directive', optional=True)
        return '<div class="text-error">{0}</div>'.format(msg)
    providers = micawber.bootstrap_basic()
    return micawber.parse_text(url, providers)