本文整理汇总了Python中wordpress_xmlrpc.WordPressPost.post_status方法的典型用法代码示例。如果您正苦于以下问题:Python WordPressPost.post_status方法的具体用法?Python WordPressPost.post_status怎么用?Python WordPressPost.post_status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wordpress_xmlrpc.WordPressPost
的用法示例。
在下文中一共展示了WordPressPost.post_status方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sourcename
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import post_status [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: post_article
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import post_status [as 别名]
def post_article(self, wordpress_link, wordpress_id, wordpress_pass, articletitle, articlecategories,
articlecontent, articletags, imagelink=None):
if imagelink:
self.path = os.getcwd() + "\\00000001.jpg"
self.articlePhotoUrl = imagelink
self.wpUrl = wordpress_link
self.wpUserName = wordpress_id
self.wpPassword = wordpress_pass
# Download File
f = open(self.path, 'wb')
f.write(urllib.urlopen(self.articlePhotoUrl).read())
f.close()
# Upload to WordPress
client = Client(self.wpUrl, self.wpUserName, self.wpPassword)
filename = self.path
# prepare metadata
data = {
'name': 'picture.jpg', 'type': 'image/jpg',
}
# read the binary file and let the XMLRPC library encode it into base64
with open(filename, 'rb') as img:
data['bits'] = xmlrpc_client.Binary(img.read())
response = client.call(media.UploadFile(data))
attachment_id = response['id']
# Post
post = WordPressPost()
post.title = articletitle
post.content = articlecontent
post.terms_names = {'post_tag': articletags, 'category': articlecategories}
post.post_status = 'publish'
post.thumbnail = attachment_id
post.id = client.call(posts.NewPost(post))
print 'Post Successfully posted. Its Id is: ', post.id
else:
self.wpUrl = wordpress_link
self.wpUserName = wordpress_id
self.wpPassword = wordpress_pass
# Upload to WordPress
client = Client(self.wpUrl, self.wpUserName, self.wpPassword)
# Post
post = WordPressPost()
post.title = articletitle
post.content = articlecontent
post.terms_names = {'post_tag': articletags, 'category': articlecategories}
post.post_status = 'publish'
post.id = client.call(posts.NewPost(post))
print 'Post Successfully posted. Its Id is: ', post.id
示例3: postToWordpress
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import post_status [as 别名]
def postToWordpress(text, thisDay, wp):
"""Publishes the blog post to WordPress.
Arguments:
text -- HTML text body of the post.
thisDay -- The date of the post, which will also become the title.
Return:
post.title -- The title of the WordPress post.
True / False -- Whether or not the post was successfully posted.
"""
post = WordPressPost()
post.title = dateToString(thisDay)
post.content = text
post.date = (thisDay +
datetime.timedelta(0,0,0,0,30,23)) # 6:30pm, EST
post.post_status = 'publish'
post.terms_names = {
'post_tag': ['Journal Entry', 'Food'],
'category': ['Journal']
}
try:
wp.call(NewPost(post))
except:
return (post.title,False)
return (post.title, True)
示例4: post
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import post_status [as 别名]
def post(self):
from lxml import etree
try:
self.ui.label.setText("Importing necessary modules...")
from wordpress_xmlrpc import Client, WordPressPost
status = 1
except:
status = 0
if(status==1):
from wordpress_xmlrpc.methods.posts import GetPosts, NewPost
from wordpress_xmlrpc.methods.users import GetUserInfo
self.ui.label.setText("Imported modules...")
data = etree.parse("config.xml")
user = data.find("user").text
url = data.find("url").text
pwd = data.find("pass").text
self.ui.label.setText("Imported data...")
try:
wp = Client(url+"/xmlrpc.php", user, pwd)
except:
status = 0
if (status == 1):
post = WordPressPost()
post.content = str(self.ui.BodyEdit.toPlainText())
post.title = str(self.ui.TitleEdit.text())
post.content = post.content + "<br><small><i>via QuickPress</i></small></br>"
post.post_status = 'publish'
wp.call(NewPost(post))
self.ui.label.setText("Published")
else:
self.ui.label.setText("Check Internet Connection and try again...")
else:
self.ui.label.setText("module(wordpress_xmlrpc) not found, you can install manually from terminal using pip install python-wordpress-xmlrpc")
示例5: Publish_Post
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import post_status [as 别名]
def Publish_Post(title,body):
# Connect to Word Press POST API
obj=setup('https://hackingjournalismtest.wordpress.com/xmlrpc.php', 'contentmagicalsystem','aA9&cG^%[email protected]&h')
post = WordPressPost()
if len(title) == 0 :
raise("Cant Process the request")
return "Empty title requested"
if len(body) == 0:
rasie("Cant Process the request")
return "Empty body requested"
'''
Future or Next in line
Better data validations
Have some other quality checks for non ascii charecters and valdiate unicode letters if required
Request type validation (old vs new)
check if title already exist and update postif required
'''
post.title=title
post.content=body
# Make post visible ,status should be publish
post.post_status = 'publish'
# API call to push it to word press
post.id=wp.call(NewPost(post))
#return "Post created with id ",post.id
return post.id
示例6: build_news_message
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import post_status [as 别名]
def build_news_message(news):
post = WordPressPost()
post.title = news.brief_comment
converted_video_url = None
if news.video_url is not None:
converted_video_url = convert_youku_video_url(news.video_url)
content_items = {'content' : _normalize_content(news.recommended_reason)}
if news.screenshot_path_1:
content_items['screenshot_path_1'] = settings.MEDIA_URL + news.screenshot_path_1.name
if news.screenshot_path_2:
content_items['screenshot_path_2'] = settings.MEDIA_URL + news.screenshot_path_2.name
if news.screenshot_path_3:
content_items['screenshot_path_3'] = settings.MEDIA_URL + news.screenshot_path_3.name
if news.screenshot_path_4:
content_items['screenshot_path_4'] = settings.MEDIA_URL + news.screenshot_path_4.name
content_items['video_url'] = converted_video_url
post.content = str(render_to_string('news_web.tpl', content_items))
post.terms_names = {
'category' : [u'新游预告']
}
if news.screenshot_path_1.name != '':
post.custom_fields = []
post.custom_fields.append({'key':'post_image','value':settings.MEDIA_URL + news.screenshot_path_1.name})
post.post_status = 'publish'
return WebMessage(news.id, post)
示例7: create_post
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import post_status [as 别名]
def create_post(title, text="", url="", image_url=""):
shortened_url = shorten_link(url) if url else ""
url_html = "<a href='{shortened_url}'>{url}</a><br/>".format(url=url, shortened_url=shortened_url) if url else ""
image_html = "<img style='width: 100%; height: auto;' src='{image_url}'></img><br/>".format(image_url=image_url) if image_url else ""
text_html = "<p>" + text + "</p>" + "<br/>" if text else ""
content = url_html + image_html + text_html
# https://developer.wordpress.com/docs/api/1.1/post/sites/%24site/posts/new/
# http://python-wordpress-xmlrpc.readthedocs.org/en/latest/examples/posts.html
post = WordPressPost()
post.title = title
post.content = content
post.author = "testaccount"
post.post_status = "publish"
# post.terms_names = {
# 'post_tag': ['test', 'firstpost'],
# 'category': ['Introductions', 'Tests']
# }
try:
redditsync.wordpress.wp.call(NewPost(post))
except Exception as err:
logging.error(str(err))
sys.exit()
示例8: createPost
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import post_status [as 别名]
def createPost(image):
localFilename = 'images/{0}'.format(image + '.jpg')
print 'image is: {0}'.format(localFilename)
imageTimestamp = getTimestamp(image)
wpFilename = image + imageTimestamp + '.jpg'
data = {
'name': '{0}'.format(wpFilename),
'type': 'image/jpeg',
}
with open(localFilename, 'rb') as img:
data['bits'] = xmlrpc_client.Binary(img.read())
response = client.call(media.UploadFile(data))
print 'response is: {0}'.format(response)
month = strftime("%m", gmtime())
post = WordPressPost()
post.title = country + city
post.content = '[caption id="" align="alignnone" width ="640"]<img src="http://www.backdoored.io/wp-content/uploads/2016/' + month + '/' + wpFilename.replace(":", "") + '">' + ipAddress + hostnames + isp + timestamp + country + city + '[/caption]'
post.id = client.call(NewPost(post))
post.post_status = 'publish'
client.call(EditPost(post.id, post))
示例9: doPost
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import post_status [as 别名]
def doPost(self):
post = WordPressPost()
# get all post properties
post.title = str(unicode(self.lnEdit_PostTitle.text()))
post.content = str(unicode(self.txtEdit_PostContent.toPlainText()))
tag = unicode(self.lnEditPostTags.text())
category = unicode(self.lnEditPostCategories.text())
# use ',' split multi-tag or category
if ',' in tag: tag = tag.split(',')
if ',' in category: category = category.split(',')
post.terms_names = {
'post_tag': tag,
'category': category
}
post.post_status = str(self.cb_post_status.currentText())
try:
# new post or page-type post
if (self._newPost_):
post.id = self.wp.call(posts.NewPost(post))
QtGui.QMessageBox.information(self, 'info', "Post success!", QtGui.QMessageBox.Ok)
else:
print 'edit...'
# edit a post
if self._postId_ != None:
self.wp.call(posts.EditPost(self._postId_, post))
QtGui.QMessageBox.information(self, 'info', "Edit success!", QtGui.QMessageBox.Ok)
except Exception, e:
QtGui.QMessageBox.information(self, 'err', str(e), QtGui.QMessageBox.Ok)
示例10: build_evaluation_message
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import post_status [as 别名]
def build_evaluation_message(evaluation):
post = WordPressPost()
post.title = evaluation.title
post.content = str(render_to_string('evaluation_web.tpl', {
'id' : evaluation.id,
'content' : _normalize_content(evaluation.recommended_reason),
'icon' : settings.MEDIA_URL + evaluation.icon.name,
'platforms' : _get_game_evaluation_platforms(evaluation),
'android_download_url' : evaluation.android_download_url,
'iOS_download_url' : evaluation.iOS_download_url,
'evaluation_content' : evaluation.content,
'rating' : evaluation.rating,
}))
post.terms_names = {
'category' : [u'游戏测评'],
'post_tag' : _get_game_evaluation_tags(evaluation)
}
if evaluation.icon.name != '':
post.custom_fields = []
post.custom_fields.append({'key':'post_image','value':settings.MEDIA_URL + evaluation.icon.name})
post.post_status = 'publish'
return WebMessage(evaluation.id, post)
示例11: build_game_message
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import post_status [as 别名]
def build_game_message(game):
post = WordPressPost()
post.title = '%s - %s' % (game.name, game.brief_comment)
converted_video_url = None
if game.video_url is not None:
converted_video_url = convert_youku_video_url(game.video_url)
post.content = str(render_to_string('game_web.tpl', {
'content' : _normalize_content(game.recommended_reason),
'icon' : settings.MEDIA_URL + game.icon.name,
'category' : game.category.name,
'size' : game.size,
'platforms' : _get_game_platforms(game),
'id' : game.id,
'android_download_url' : game.android_download_url,
'iOS_download_url' : game.iOS_download_url,
'screenshot_path_1' : settings.MEDIA_URL + game.screenshot_path_1.name,
'screenshot_path_2' : settings.MEDIA_URL + game.screenshot_path_2.name,
'screenshot_path_3' : settings.MEDIA_URL + game.screenshot_path_3.name,
'screenshot_path_4' : settings.MEDIA_URL + game.screenshot_path_4.name,
'video_url' : converted_video_url
}))
post.terms_names = {
'category' : [game.category.name],
'post_tag' : _get_game_tags(game)
}
if game.screenshot_path_1.name != '':
post.custom_fields = []
post.custom_fields.append({'key':'post_image','value':settings.MEDIA_URL + game.screenshot_path_1.name})
post.post_status = 'publish'
return WebMessage(game.id, post)
示例12: post_to_wordpress
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import post_status [as 别名]
def post_to_wordpress(self, story):
# Get number of posts to number the story title, i.e. if this is the 6th story
# that will get posted the title will be "Story 6"
print "Retrieving posts"
# get pages in batches of 20
num_of_post = 0
offset = 0
increment = 20
while True:
posts_from_current_batch = self.wp.call(posts.GetPosts({'number': increment, 'offset': offset}))
if len(posts_from_current_batch) == 0:
break # no more posts returned
else:
num_of_post += len(posts_from_current_batch)
offset = offset + increment
print num_of_post
# Create new post
print "Creating new post..."
post = WordPressPost()
post.title = 'Story %d' % (num_of_post + 1) # incrementing the number of post by 1
# convert each sentence to string, and join separated by a space.
post.content = " ".join(map(str, story))
post.id = self.wp.call(posts.NewPost(post))
# publish it
print "Publishing"
post.post_status = 'publish'
self.wp.call(posts.EditPost(post.id, post))
print "Done!"
示例13: build_collection_message
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import post_status [as 别名]
def build_collection_message(collection):
post = WordPressPost()
post.title = collection.title
games = []
for game in collection.games.all():
games.append({
'name' : game.name,
'brief_comment' : game.brief_comment,
'icon' : settings.MEDIA_URL + game.icon.name,
'category' : game.category.name,
'size' : game.size,
'platforms' : _get_game_platforms(game),
'id' : game.id,
'android_download_url' : game.android_download_url,
'iOS_download_url' : game.iOS_download_url,
'rating' : game.rating,
'recommended_reason' : _normalize_content(game.recommended_reason)
})
post.content = str(render_to_string('collection_web.tpl', {
'content' : _normalize_content(collection.recommended_reason),
'cover' : settings.MEDIA_URL + collection.cover.name,
'games' : games
}))
post.terms_names = {
'category' : [u'游戏合集']
}
post.post_status = 'publish'
return WebMessage(collection.id, post)
示例14: prepare_post
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import post_status [as 别名]
def prepare_post(event):
post = WordPressPost()
post.title = event['Headline']
body_string = '''<p id="pagekeeper"><img src='http://free.pagepeeker.com/v2/thumbs.php?size=x&url={}'><br/>{}</p><p>{}</p>'''.format(event["Media"], event["Media Credit"].replace("\n", ""), event["Text"])
post.content = body_string
post.date = parser.parse(event['Start Date'])
post.terms_names = {'post_tag': [event['Tag']]}
post.post_status = 'publish'
return post
示例15: postInWordpress
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import post_status [as 别名]
def postInWordpress(self, title, content, ):
post = WordPressPost()
post.title = title
post.content = content
post.post_status = 'publish'
post.terms_names = {'post_tag': ['leak', 'pastebin leak', 'hack leak', 'hack'],'category': ['Leaks']}
post.id = self.wordpress.call(NewPost(post))
p = self.wordpress.call(GetPosts())[0]
return p.link