本文整理汇总了Python中wordpress_xmlrpc.WordPressPost.user方法的典型用法代码示例。如果您正苦于以下问题:Python WordPressPost.user方法的具体用法?Python WordPressPost.user怎么用?Python WordPressPost.user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wordpress_xmlrpc.WordPressPost
的用法示例。
在下文中一共展示了WordPressPost.user方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sourcename
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import user [as 别名]
def sourcename(url, cat1=None, cat2=None, cat3=None, d=True):
html = getPage(url, "page1.html")
os.remove('pages/page1.html')
title = html.select('h1')[0].text
first_para = html.select('.story-content > p:nth-of-type(1)')[0].text
second_para = html.select('.story-content > p:nth-of-type(2)')[0].text
try:
image = html.select('.image > img')[0].get('src')
except Exception:
image = None
wp = Client('http://www.domain.com/xml-rpc.php', 'username', 'password')
if image:
filename = 'http://www.livemint.com' + image
path = os.getcwd() + "\\00000001.jpg"
f = open(path, 'wb')
f.write(urllib.urlopen(filename).read())
f.close()
# prepare metadata
data = {
'name': 'picture.jpeg',
'type': 'image/jpeg', # mimetype
}
with open(path, 'rb') as img:
data['bits'] = xmlrpc_client.Binary(img.read())
response = wp.call(media.UploadFile(data))
post = WordPressPost()
post.title = title
post.user = 14
post.post_type = "post"
post.content = first_para + '\n' + '\n' + second_para
if d:
post.post_status = "draft"
else:
post.post_status = "publish"
if image:
attachment_id = response['id']
post.thumbnail = attachment_id
post.custom_fields = []
post.custom_fields.append({
'key': 'custom_source_url',
'value': url
})
if cat1:
cat1 = wp.call(taxonomies.GetTerm('category', cat1))
post.terms.append(cat1)
if cat2:
cat2 = wp.call(taxonomies.GetTerm('category', cat2))
post.terms.append(cat2)
if cat3:
cat3 = wp.call(taxonomies.GetTerm('category', cat3))
post.terms.append(cat3)
addpost = wp.call(posts.NewPost(post))
示例2: create_wordpress_draft
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import user [as 别名]
def create_wordpress_draft(publish_target, title, html, tags):
post = WordPressPost()
today = datetime.date.today()
post.title = title
post.content = html
client = Client( publish_target["url"] + "/xmlrpc.php", publish_target["username"], publish_target["password"])
category = client.call(taxonomies.GetTerm('category', publish_target["default_category_id"]))
post.terms.append(category)
post.user = publish_target["default_user_id"]
post.terms_names = {'post_tag': tags}
post.comment_status = 'open'
post.id = client.call(posts.NewPost(post))
return post
示例3: publish
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import user [as 别名]
def publish(pic, title, content):
'''
publish a post and set to open to comment and ping(trackback)
'''
attachment = upload(pic)
wp_client = Client(rpc_service_url, user, password)
post = WordPressPost()
post.title = title
post.content = "%s\n\n<a href='%s'><img class='alignnone size-full wp-image-%s' alt='%s' src='%s' /></a>" % (content, attachment['url'], attachment['id'], attachment['file'], attachment['url'])
#post.tags='test, test2'
#post.categories=['pet','picture']
post.thumbnail = attachment['id']
#change status to publish
post.id = wp_client.call(posts.NewPost(post))
post.post_status = 'publish'
post.comment_status = 'open'
post.ping_status = 'open'
post.user = account_ids[r.randint(0, len(account_ids)-1)]
wp_client.call(posts.EditPost(post.id, post))
return post.id
示例4: entry_to_wppost
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import user [as 别名]
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