本文整理汇总了Python中wordpress_xmlrpc.WordPressPost类的典型用法代码示例。如果您正苦于以下问题:Python WordPressPost类的具体用法?Python WordPressPost怎么用?Python WordPressPost使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WordPressPost类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_collection_message
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)
示例2: post
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")
示例3: post_to_wordpress
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!"
示例4: create_post
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()
示例5: Publish_Post
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: createPost
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))
示例7: create_post_from_file
def create_post_from_file(a_file):
post = WordPressPost()
file_content = get_content_for_file(a_file)
match = yaml_match_from_post_data(file_content)
yaml_data = extract_yaml_data_using_match(file_content, match)
add_meta_info_from_yaml_to_post(yaml_data, post, a_file)
post.content = file_content[match.end():].strip()
return post
示例8: make_post
def make_post(content, wp):
start = datetime.datetime.utcnow()
end = start + datetime.timedelta(7)
dates = (start.strftime('%b %d'), end.strftime('%b %d'))
post = WordPressPost()
post.title = "This week's schedule (%s - %s)" % dates
post.content = content
post.post_status = 'draft'
wp.call(NewPost(post))
示例9: build
def build(self, title, content, categories=[], tags=[]):
post = WordPressPost()
post.title = title
post.content = content
post.terms_names = {
'post_tag': tags,
'category': categories,
}
post.post_status = 'publish'
return NewPost(post)
示例10: newPost
def newPost(title, content, tags, cats):
post = WordPressPost()
post.title = title
post.content = content
#post.post_status = 'publish'
post.terms_names = {
'post_tag': tags,
'category': cats
}
wp.call(NewPost(post))
示例11: post_file
def post_file(wp, f, t, y, m, d):
p = WordPressPost()
p.title = t
p.content = slurp(f)
# 9am zulu is early Eastern-Pacific
p.date = p.date_modified = datetime(y,m,d,9)
p.post_status = 'publish'
p.comment_status = 'closed'
if wp:
wp.call(NewPost(p))
示例12: toWordPressPost
def toWordPressPost(self):
post = WordPressPost()
if self.title:
post.title = self.title
if self.content:
post.content = self.content
post.post_status = 'publish'
return post
示例13: createPost
def createPost(self, post_title, post_content):
# create draft
post = WordPressPost()
post.title = post_title
post.content = post_content
post.id = self.wordpress.call(posts.NewPost(post))
# set status to be update
#post.post_status = 'publish'
#self.wordpress.call(posts.EditPost(post.id, post))
return post
示例14: postDraft
def postDraft(self, title, body):
'''
Creates a draft with title and graph
Currently both title and graph are just strings
'''
post = WordPressPost()
post.title = title
post.content = body
# post,terms_names = {
# 'post_tag': ['test'],
# 'category': ['testCat']}
self.wp.call(NewPost(post))
示例15: _make_post
def _make_post(client, title, content):
"""
Make a post on the wordpress site for this content item.
"""
print 'MAKING POST FOR:', title
post = WordPressPost()
post.title = title
post.content = content
post.terms_names = {
'post_tag': ['test', 'firstpost'],
'category': ['Introductions', 'Tests']
}
post.publish = True
client.call(NewPost(post))