Пример #1
0
 def test_widget(self):
     html = markup(_text)
     soup = BeautifulSoup(html)
     widgets = soup.find_all('widget')
     self.assertEqual(1, len(widgets))
     self.assertEqual(
         'widget option1 option2',
         widgets[0].text)
Пример #2
0
    def from_metaweblog(cls, struct, post_type='post', is_edit=False):
        """Receive metaWeblog RPC struct and initialize a Post.
           Used both by migrate_from_wordpress and when receiving a new or
           edited post from MarsEdit.
        """
        title = struct.get('title', '')

        meta_description = struct.get('mt_excerpt', '')
        if len(meta_description) > 155:
            raise ValueError("Description is %d chars, max 155" %
                             len(meta_description))

        if 'mt_keywords' in struct:
            tags = [
                tag.strip() for tag in struct['mt_keywords'].split(',')
                if tag.strip()
            ]
        else:
            tags = None

        slug = (slugify.slugify(struct['wp_slug'])
                if struct.get('wp_slug') else slugify.slugify(title))

        description = struct.get('description', '')
        status = (struct.get('post_status') or struct.get('page_status')
                  or 'publish')

        if 'date_modified_gmt' in struct:
            tup = struct['date_modified_gmt'].timetuple()
            mod = utc_tz.localize(datetime.datetime(*tup[0:6]))
        else:
            mod = datetime.datetime.utcnow()

        body = markup.markup(description)

        rv = cls(
            title=title,
            # Format for display
            body=body,
            plain=plain.plain(body),
            summary=summarize.summarize(body, 200),
            original=description,
            meta_description=meta_description,
            tags=tags,
            slug=slug,
            type=post_type,
            status=status,
            wordpress_id=struct.get('postid'),
            mod=mod)

        if not is_edit and 'date_created_gmt' in struct:
            # TODO: can fail if two posts created in same second, add random
            #   suffix to ObjectId
            date_created = datetime.datetime.strptime(
                struct['date_created_gmt'].value, "%Y%m%dT%H:%M:%S")
            rv.id = ObjectId.from_datetime(date_created)

        return rv
Пример #3
0
    def from_metaweblog(
        cls, struct, post_type='post', is_edit=False
    ):
        """Receive metaWeblog RPC struct and initialize a Post.
           Used both by migrate_from_wordpress and when receiving a new or
           edited post from MarsEdit.
        """
        title = struct.get('title', '')

        # We expect MarsEdit to set categories with mt_setPostCategories()
        assert 'categories' not in struct

        if 'mt_keywords' in struct:
            tags = [
                tag.strip() for tag in struct['mt_keywords'].split(',')
                if tag.strip()
            ]
        else:
            tags = None


        slug = (
            slugify.slugify(struct['wp_slug'])
            if struct.get('wp_slug')
            else slugify.slugify(title))

        description = struct.get('description', '')
        status = struct.get('post_status', 'publish')
        if 'date_modified_gmt' in struct:
            tup = struct['date_modified_gmt'].timetuple()
            mod = utc_tz.localize(datetime.datetime(*tup[0:6]))
        else:
            mod = datetime.datetime.utcnow()

        body = markup.markup(description)

        rv = cls(
            title=title,
            # Format for display
            body=body,
            summary=summarize.summarize(body, 200),
            original=description,
            tags=tags,
            slug=slug,
            type=post_type,
            status=status,
            wordpress_id=struct.get('postid'),
            mod=mod
        )

        if not is_edit and 'date_created_gmt' in struct:
            # TODO: can fail if two posts created in same second, add random
            #   suffix to ObjectId
            date_created = datetime.datetime.strptime(
                struct['date_created_gmt'].value, "%Y%m%dT%H:%M:%S")
            rv.id = ObjectId.from_datetime(date_created)

        return rv
def main(args):
    db = pymongo.MongoClient().motorblog

    print 'Updating', db.posts.count(), 'posts'
    print

    for post in db.posts.find().sort('_id'):
        print post['title'], post['type'], post['mod']
        original = migrate_from_cMarkdown_to_markdown(post['original'])
        post['original'] = original
        post['body'] = markup.markup(original)
        post['mod'] = datetime.datetime.utcnow()

        if not args.dry_run:
            print 'saving'
            db.posts.save(post)
def main(args):
    db = pymongo.MongoClient().motorblog

    print 'Updating', db.posts.count(), 'posts'
    print

    for post in db.posts.find().sort('_id'):
        print post['title'], post['type'], post['mod']
        original = migrate_from_cMarkdown_to_markdown(post['original'])
        post['original'] = original
        post['body'] = markup.markup(original)
        post['mod'] = datetime.datetime.utcnow()

        if not args.dry_run:
            print 'saving'
            db.posts.save(post)
Пример #6
0
 def test_widget(self):
     html = markup(_text)
     soup = BeautifulSoup(html)
     widgets = soup.find_all('widget')
     self.assertEqual(1, len(widgets))
     self.assertEqual('widget option1 option2', widgets[0].text)