Ejemplo n.º 1
1
def wordPressPost():
	for i in range(38):
		content = """<iframe src="//www.youtube-nocookie.com/embed/""" + urls[i] + """?rel=0" \
height="360" width="640" allowfullscreen="" frameborder="0"></iframe>"""

		post = WordPressPost()
		post.title = titles[i]
		post.content = content
		print titles[i]
		print content
		post.link = 'http://medtwice.com/pregnancy-by-week-week-'+str(i+4)
		post.post_status = 'publish'
		category = wp.call(taxonomies.GetTerm('category', 44))
		post.terms.append(category)
		post.id = wp.call(NewPost(post))
Ejemplo n.º 2
0
 def process_item(self, item, spider):
     wp = Client('https://www.along.party/xmlrpc.php', '', '')
     post = WordPressPost()
     post.title = item['title']
     post.user = item['author']
     post.link = item['url']
     # post.date = item['publish_time']
     post.content = item['body']
     post.content = u"%s \n 本文转载自 <a href='%s'> %s</a> " % (
         item['body'], item['url'], item['title'])
     post.post_status = 'publish'
     post.terms_names = {'post_tag': 'Python', 'category': 'Python'}
     wp.call(NewPost(post))
Ejemplo n.º 3
0
def create_post_obj(title, content, link, post_status, terms_names_post_tag,
                    terms_names_category):
    post_obj = WordPressPost()
    post_obj.title = title
    post_obj.content = content
    post_obj.link = link
    post_obj.post_status = post_status
    post_obj.comment_status = "open"
    print(post_obj.link)
    post_obj.terms_names = {
        #文章所属标签,没有则自动创建
        'post_tag': terms_names_post_tag,
        #文章所属分类,没有则自动创建
        'category': terms_names_category
    }

    return post_obj
Ejemplo n.º 4
0
 def process_item(self, item, spider):
     wp_filename = item.filename('wp')
     if os.path.exists(wp_filename):
         with open(wp_filename) as fh:
             post = pickle.load(fh)
             fh.close()
             # #
             # Here one might update or fix things
             if False:
                 post.terms_names = {
                     'category': [item['source_name'].title()],
                     'post_tag': get_place_post_tag_names(item['place'])
                 }
                 self.client.call(posts.EditPost(post.id, post))
                 pass
             pass
         pass
     else:
         post = WordPressPost()
         post.title = item['headline']
         try:
             post.content = item['body']
         except KeyError:
             return None
         try:
             item['place']
         except KeyError:
             item['place'] = ""
         post.terms_names = {
             'category': [item['source_name'].title()],
             'post_tag': get_place_post_tag_names(item['place'])
         }
         post.link = item['source_url']
         post.date = item['time']
         post.post_status = 'publish'
         post.id = self.client.call(posts.NewPost(post))
         with open(wp_filename, 'wb') as fh:
             pickle.dump(post, fh)
             fh.close()
         pass
     return item
     pass
Ejemplo n.º 5
0
def entry_to_wppost(entry, client):
    post             = WordPressPost()
    # Convert entry values to Post value
    post.user        = get_author_by_display_name(entry.author, client)
    post.date        = entry.published_parsed
    post.post_status = "draft"
    post.title       = entry.title
    post.content     = entry.content[0].value
    post.excerpt     = entry.summary
    post.link        = entry.link
    # There is some given tags
    if len(entry.tags):
        entry.tags = [t.term for t in entry.tags]
        # Add category (with the first tag)
        post.terms_names = {
            'category': entry.tags[0:1],
            'post_tag': [],
        }
        # Add tags
        if len(entry.tags) > 1: post.terms_names['post_tag'] = entry.tags[1:]
    return post
Ejemplo n.º 6
0
                continue
            if not tag: continue
            if getImageSrc(tag) != '':
                img_id = imageUpload(getImageSrc(tag), alias, i=i)
            else:
                continue
            img_tag = '<!-- wp:image {"id":%s,"sizeSlug":"large"} --><figure class="wp-block-image size-large"><img src="%s" alt="" class="wp-image-%s"/></figure><!-- /wp:image -->' % (
                img_id['id'], img_id['link'], img_id['id'])
            content += img_tag
            i += 1
            continue

        try:
            content += tag.prettify()
        except Exception as e:
            print('Exception: %s' % e)

    img_id = imageUpload(image, alias)

    post = WordPressPost()
    post.title = soup.find(class_='article__title').text
    post.content = content
    post.mime_type = "text/html"
    post.user = 2  # WP Author ID
    post.link = alias
    post.post_type = "post"
    post.thumbnail = img_id['id']
    post.post_status = "publish"  # "draft"
    post_id = client.call(posts.NewPost(post))
    print("Post: %s (%s) Done!" % (post_id, alias))