def create_blog_pages(self, posts, blog_index, *args, **options):
        """create Blog post entries from wordpress data"""
        for post in posts:
            post_id = post.get('ID')
            title = post.get('title')
            if title:
                new_title = self.convert_html_entities(title)
                title = new_title
            slug = post.get('slug')
            description = post.get('description')
            if description:
                description = self.convert_html_entities(description)

            body = post.get('content')
            if not "<p>" in body:
                body = linebreaks(body)

            # get image info from content and create image objects
            body = self.create_images_from_urls_in_content(body)

            # author/user data
            author = post.get('author')
            user = self.create_user(author)
            categories = post.get('terms')
            # format the date
            date = post.get('date')[:10]
            try:
                new_entry = BlogPage.objects.get(slug=slug)
                new_entry.title = title
                new_entry.body = body
                new_entry.owner = user
                new_entry.save()
            except BlogPage.DoesNotExist:
                new_entry = blog_index.add_child(instance=BlogPage(
                    title=title, slug=slug, search_description="description",
                    date=date, body=body, owner=user))
            featured_image = post.get('featured_image')
            if featured_image is not None:
                title = post['featured_image']['title']
                source = post['featured_image']['source']
                path, file_ = os.path.split(source)
                source = source.replace('stage.swoon', 'swoon')
                try:
                    remote_image = urllib.request.urlretrieve(
                        self.prepare_url(source))
                    width = 640
                    height = 290
                    header_image = Image(title=title, width=width, height=height)
                    header_image.file.save(
                        file_, File(open(remote_image[0], 'rb')))
                    header_image.save()
                except UnicodeEncodeError:
                    header_image = None
                    print('unable to set header image {}'.format(source))
            else:
                header_image = None
            new_entry.header_image = header_image
            new_entry.save()
            if categories:
                self.create_categories_and_tags(new_entry, categories)
            if self.should_import_comments:
                self.import_comments(post_id, slug)
def create_blog_pages ( self , posts , blog_index , * args , ** options ) : for post in posts : post_id = post . get ( 'ID' ) title = post . get ( 'title' ) if title : new_title = self . convert_html_entities ( title ) title = new_title slug = post . get ( 'slug' ) description = post . get ( 'description' ) if description : description = self . convert_html_entities ( description ) body = post . get ( 'content' ) if not "<p>" in body : body = linebreaks ( body ) body = self . create_images_from_urls_in_content ( body ) author = post . get ( 'author' ) user = self . create_user ( author ) categories = post . get ( 'terms' ) date = post . get ( 'date' ) [ : 10 ] try : new_entry = BlogPage . objects . get ( slug = slug ) new_entry . title = title new_entry . body = body new_entry . owner = user new_entry . save ( ) except BlogPage . DoesNotExist : new_entry = blog_index . add_child ( instance = BlogPage ( title = title , slug = slug , search_description = "description" , date = date , body = body , owner = user ) ) featured_image = post . get ( 'featured_image' ) if featured_image is not None : title = post [ 'featured_image' ] [ 'title' ] source = post [ 'featured_image' ] [ 'source' ] path , file_ = os . path . split ( source ) source = source . replace ( 'stage.swoon' , 'swoon' ) try : remote_image = urllib . request . urlretrieve ( self . prepare_url ( source ) ) width = 640 height = 290 header_image = Image ( title = title , width = width , height = height ) header_image . file . save ( file_ , File ( open ( remote_image [ 0 ] , 'rb' ) ) ) header_image . save ( ) except UnicodeEncodeError : header_image = None print ( 'unable to set header image {}' . format ( source ) ) else : header_image = None new_entry . header_image = header_image new_entry . save ( ) if categories : self . create_categories_and_tags ( new_entry , categories ) if self . should_import_comments : self . import_comments ( post_id , slug )
create Blog post entries from wordpress data