本文整理汇总了Python中wordpress_xmlrpc.WordPressPost.slug方法的典型用法代码示例。如果您正苦于以下问题:Python WordPressPost.slug方法的具体用法?Python WordPressPost.slug怎么用?Python WordPressPost.slug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wordpress_xmlrpc.WordPressPost
的用法示例。
在下文中一共展示了WordPressPost.slug方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testUpdate
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import slug [as 别名]
def testUpdate(pid):
client = initClient()
post = WordPressPost()
post.title = 'My new title update 2'
post.content = 'This is the body of my new post.'
post.slug= 'helloword'
post.post_type = 'post'
post.post_status = 'draft'
print client.call(posts.EditPost(pid, post))
示例2: post
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import slug [as 别名]
def post(wp, old_post, title, content, rtcprof, img_info):
from wordpress_xmlrpc import WordPressPost
from wordpress_xmlrpc.methods.posts import NewPost, EditPost
if old_post:
post = old_post
else:
post = WordPressPost()
post.title = title
post.content = content
post.terms_names = {
'post_tag': [rtcprof.name, 'RTC'],
'category': ['RTComponents', rtcprof.basicInfo.category]
}
post.slug = rtcprof.name
n = datetime.datetime.now()
year = n.year
month = n.month
day = n.day
hour = n.hour
if n.hour < 9:
day = day - 1
hour = hour + 24
if day == 0:
month = month - 1
if month == 0:
month = 12
year = year -1
if month in [4, 6, 9, 11]:
day = 30
elif month == 2:
day = 28
else:
day = 31
hour = hour - 9
post.date = datetime.datetime(year, month, day, hour, n.minute, n.second)
post.post_status = 'publish'
if img_info:
post.thumbnail = img_info['id']
else:
post.thumbnail = old_post.thumbnail
if old_post: # Edit Mode
wp.call(EditPost(post.id, post))
else:
wp.call(NewPost(post))
示例3: parseDocument
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import slug [as 别名]
def parseDocument(filename):
lines = open(filename, 'r').readlines()
values = {'title':'', 'permalink':'', 'layout':'post', 'tags':'', 'categories':'default', 'published': 'false'}
start = False
config = False
for i in range(len(lines)):
line = lines[i].strip()
if config == False:
if line == '---':
if (start == False):
start = True
else: # end
if (values['title'] == '' or values['permalink'] == ''):
printf('title and permalink should not be null!\n'); exit()
else:# config ok
config = True
else:
try:
key = line[:line.find(':')]
value = line[line.find(':')+1:]
values[key] = value.strip()
except:
printf('config failed! (key, value) = (' + key + ', ' + value + ')\n');exit()
else: #config ok
while len(lines[i]) <= 1: #filter first blank lines
i+=1
rawcontent = parseMedia(lines[i:])
rawfilename = filename[:-3] + '.raw.id-'
open(rawfilename, 'w').writelines(rawcontent)
post = WordPressPost()
post.title = values['title']
post.slug = values['permalink']
post.content = pandocTool.md2html(rawfilename)
post.post_type = values['layout']
post.post_status = 'publish' if values['published'].lower() == 'true' else 'draft'
post.comment_status = 'open' #default
post.pint_status = 'open' #default
post.terms_names = {}
#values['tags'] = values['tags'].replace(',', ',') compatible with jekyll, use blank
#values['categories'] = values['categories'].replace(',', ',')
if len(values['tags']) > 0:
post.terms_names['post_tag'] = [ tag.strip() for tag in values['tags'].split() if len(tag) > 0]
if len(values['categories']) > 0:
post.terms_names['category'] = [ cate.strip() for cate in values['categories'].split() if len(cate) > 0]
return post
示例4: addItemsToWordpress
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import slug [as 别名]
def addItemsToWordpress( self ):
items = self.items
if items:
wp = Client('http://' + self.wpinfo['website'] + '/xmlrpc.php', self.wpinfo['user'], self.wpinfo['pass'])
pass
for item in items:
self.log.info("[ Scrapper {} ] - [ Publishing \"{}\" into WP ]".format( self.table, item["title"] ))
now = time.strftime("%c")
post = WordPressPost()
post.terms_names = {
'category': ['Scrapped'] # This need to be changed in next release
}
post.title = '{}'.format(item['title'])
if item['slug']:
post.slug = item['slug']
if item['image_url']:
call(['curl',item['image_url'].replace(' ','%20'),'-o','image.jpg.scrapper_data'])
filename = 'image.jpg.scrapper_data'
data = {
'name': 'image.jpg',
'type': 'image/jpeg', # mimetype
}
with open(filename, 'rb') as img:
data['bits'] = xmlrpc_client.Binary(img.read())
response = wp.call(media.UploadFile(data))
attachment_id = response['id']
post.thumbnail = attachment_id
content = ''
if item['content']:
content += '{}'.format(item['content'])
content += 'Source: <a href="{}">{}</a>\n\n'.format(item['url'],item['referer'])
post.content = content
wp.call(NewPost(post))
示例5: add_or_edit_wp_post
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import slug [as 别名]
def add_or_edit_wp_post(title, content, slug, more_info_url, local_img_file):
# first upload the image
if local_img_file:
data = {
'name': local_img_file.split('/')[-1],
'type': 'image/jpg', # mimetype
}
# read the binary file and let the XMLRPC library encode it into base64
with open(local_img_file, 'rb') as img:
data['bits'] = xmlrpc_client.Binary(img.read())
response = wp.call(media.UploadFile(data))
attachment_id = response['id']
# now post the post and the image
post = WordPressPost()
post.post_type = 'post' # stupid effing theme
post.title = title
post.content = content
post.post_status = 'publish'
post.slug = slug
if local_img_file:
post.thumbnail = attachment_id
if not get_wp_post_id(slug):
# this is a new post
wp.call(NewPost(post))
msg = "posted"
else:
# this post exists, update it
post.id = get_wp_post_id(slug)
wp.call(EditPost(post.id, post))
msg = "edited"
print "%s %s as %s" % (msg, title, post.slug)
示例6: post
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import slug [as 别名]
def post():
#get id
post_id = re.search(':wp_id:((.*)|\n)', asc_file_read_str).group(1).strip()
#get status
post_status = re.search(':wp_status:((.*)|\n)', asc_file_read_str)
#get title
post_title = re.search(':wp_title:((.*)|\n)', asc_file_read_str)
#get slug
post_slug = re.search(':wp_slug:((.*)|\n)', asc_file_read_str)
#get category
post_category = re.search(':wp_category:((.*)|\n)', asc_file_read_str)
post_category_str = post_category.group(1).strip().split(", ")
if len(post_category_str) == 0:
post_category_str = []
elif post_category.group(1).strip() == '':
post_category_str = []
elif len(post_category_str) == 1:
post_category_str = post_category.group(1).strip(),
#get tag
post_tag = re.search(':wp_tag:((.*)|\n)', asc_file_read_str)
post_tag_str = post_tag.group(1).strip().split(", ")
if len(post_tag_str) == 0:
post_tag_str = []
elif post_tag.group(1).strip() == '':
post_tag_str = []
elif len(post_tag_str) == 1:
post_tag_str = post_tag.group(1).strip(),
#get excerpt
post_excerpt = re.search(':wp_excerpt:((.*)|\n)', asc_file_read_str)
#get thumbnail
post_thumbnail = re.search(':wp_thumbnail:((.*)|\n)', asc_file_read_str)
#post to wordpress
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods import posts
client = Client(xmlrpc_url, username, password)
post = WordPressPost()
date_ = datetime.now()
#id New or Edit
if not post_id:
post.date = date_.strftime("%s")
post.id = client.call(posts.NewPost(post))
mode = "New"
asc_file_re = re.sub(r':wp_id:((.*)|\n)', ':wp_id: ' + post.id , asc_file_read_str)
asc_file_write = open(filepath, 'w')
try:
asc_file_write.write( asc_file_re )
finally:
asc_file_write.close()
else:
post.date_modified = date_.strftime("%s")
post.id = post_id
mode = "Edit"
post.post_status = post_status.group(1).strip()
try:
post.title = post_title.group(1).strip()
except:
print 'Title is not exist'
try:
post.slug = post_slug.group(1).strip()
except:
print 'Slug is not exist'
post.content = html
try:
post.excerpt = post_excerpt.group(1).strip()
except:
post.excerpt = ''
post.terms_names = {
'category': post_category_str,
'post_tag': post_tag_str,
}
try:
post.thumbnail = post_thumbnail.group(1).strip()
except:
post.thumbnail = ''
client.call(posts.EditPost(post.id, post))
post_info = client.call(posts.GetPost(post.id, post))
#get post info from wordpress
#.........这里部分代码省略.........
示例7: upload_text
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import slug [as 别名]
def upload_text(wp, repo_name, rtcprof, html, img_info = None, test=False, build_report_filename="build_report.yaml"):
from wordpress_xmlrpc.methods import posts, taxonomies, media
sys.stdout.write(' - Uploading %s\n' % rtcprof.name)
editFlag = False
post = None
for p in all_posts:
if p.title == title:
editFlag = True
post = p
break
html = update_build_status(html, build_report_filename)
if not editFlag:
post = WordPressPost()
post.title = title
post.content = apply_language_setting(html)
post.terms_names = {
'post_tag': [rtcprof.name, 'RTC'],
'category': ['RTComponents', rtcprof.basicInfo.category]
}
post.slug = rtcprof.name
n = datetime.datetime.now()
year = n.year
month = n.month
day = n.day
hour = n.hour
if n.hour < 9:
day = day - 1
hour = hour + 24
if day == 0:
month = month - 1
if month == 0:
month = 12
year = year -1
if month in [4, 6, 9, 11]:
day = 30
elif month == 2:
day = 28
else:
day = 31
hour = hour - 9
post.date = datetime.datetime(year, month, day, hour, n.minute, n.second)
post.post_status = 'publish'
post.thumbnail = img_info['id']
post.id = wp.call(NewPost(post))
return
else: # Edit Flag
#post = WordPressPost()
post.title = title
post.content = apply_language_setting(html)
post.terms_names = {
'post_tag': [rtcprof.name, 'RTC'],
'category': ['RTComponents']
}
post.slug = rtcprof.name
n = datetime.datetime.now()
year = n.year
month = n.month
day = n.day
hour = n.hour
if n.hour < 9:
day = day - 1
hour = hour + 24
if day == 0:
month = month - 1
if month == 0:
month = 12
year = year -1
if month in [4, 6, 9, 11]:
day = 30
elif month == 2:
day = 28
else:
day = 31
hour = hour - 9
post.date = datetime.datetime(year, month, day, hour, n.minute, n.second)
post.post_status = 'publish'
post.thumbnail = img_info['id']
wp.call(posts.EditPost(post.id, post))
示例8: Client
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import slug [as 别名]
#!/usr/bin/env python3
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import GetPosts, NewPost
from config import blog_url, username, password
wp = Client(blog_url, username, password)
post = WordPressPost()
post.title = 'Testing post.title.'
post.content = 'Testing post.content. This is a test.'
post.slug = 'Testing post.slug'
post.terms_names = {
'post_tag': ['IPA', 'UK'],
'category': ['BeerBods cheat sheets']
}
wp.call(NewPost(post))
示例9: Client
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import slug [as 别名]
xmlrpc_endpoint = 'http://eidmantas.com/xmlrpc.php'
username = 'Eidmantas'
password = 'password'
wp = Client(xmlrpc_endpoint, username, password)
"""!!! DONT FORGET TO UPLOAD YOUR FILE AND CHANGE ITS NAME, OR THE VARIABLE HERE !!!"""
filename = 'your-ghost-export-file.json'
with open(filename) as f:
text = f.read()
data = json.loads(text)
for p in data['db'][0]['data']['posts']:
print p['title']
date = p.get('published_at', None)
if date is None:
p.get('created_at')
post = WordPressPost()
post.slug = p['slug']
post.content = p['html']
post.title = p['title']
post.post_status = 'publish'
try:
post.date = parse(date)
except:
exit
wp.call(NewPost(post))