本文整理汇总了Python中wordpress_xmlrpc.WordPressPost.custom_fields方法的典型用法代码示例。如果您正苦于以下问题:Python WordPressPost.custom_fields方法的具体用法?Python WordPressPost.custom_fields怎么用?Python WordPressPost.custom_fields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wordpress_xmlrpc.WordPressPost
的用法示例。
在下文中一共展示了WordPressPost.custom_fields方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_news_message
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import custom_fields [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)
示例2: build_game_message
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import custom_fields [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)
示例3: build_evaluation_message
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import custom_fields [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)
示例4: sourcename
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import custom_fields [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))
示例5: create_new_empty_wp_post
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import custom_fields [as 别名]
def create_new_empty_wp_post(component, event_category, event_map_location, location_gps):
summary = component.get('SUMMARY').encode('UTF-8', 'backslashreplace')
start_event = component.get('DTSTART').dt.strftime('%Y-%m-%d %H:%M')
end_event = component.get('DTEND').dt.strftime('%Y-%m-%d %H:%M')
end_frequency_event = component.get('DTEND').dt.strftime('%Y-%m-%d')
uid = component.get('UID').encode('UTF-8', 'backslashreplace')
event_description = component.get('DESCRIPTION')
if event_description is None:
event_description = " "
else:
event_description = component.get('DESCRIPTION').encode('UTF-8', 'backslashreplace')
# Create a new post
new_post = WordPressPost()
new_post.title = summary
new_post.content = event_description
new_post.post_type = "event"
new_post.post_status = "publish"
new_post.terms_names = {'event-category': [event_category]}
new_post.custom_fields = []
meta_adds = (['imic_event_start_dt', start_event],
['imic_event_end_dt', end_event],
['imic_event_frequency_end', end_frequency_event],
['imic_featured_event', 'no'],
['slide_template', 'default'],
['imic_event_day_month', 'first'],
['imic_event_week_day', 'sunday'],
['imic_event_frequency_type', '0'],
['imic_event_frequency', '35'],
['imic_event_registration', '0'],
['imic_custom_event_registration_target', '0'],
['imic_sidebar_columns_layout', '3'],
['imic_google_map_track', '1'],
['imic_event_address2', event_map_location],
['imic_event_map_location', location_gps],
['imic_pages_banner_overlay', '0'],
['imic_pages_banner_animation', '0'],
['imic_pages_select_revolution_from_list', '[rev_slider fsl]'],
['imic_pages_slider_pagination', 'no'],
['imic_pages_slider_auto_slide', 'no'],
['imic_pages_slider_direction_arrows', 'no'],
['imic_pages_slider_interval', '7000'],
['imic_pages_slider_effects', 'fade'],
['imic_pages_nivo_effects', 'sliceDown'],
['imic_import_uid', uid])
# Iterate over array creating meta in post
for i in meta_adds:
new_post.custom_fields.append({'key': i[0], 'value': i[1]})
return new_post
示例6: addItem
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import custom_fields [as 别名]
def addItem(self, item):
# 跳转链作为唯一标识去重
# exist_posts = self.rpcClient.call(posts.GetPosts({'custom_fields':{'key':'link_value', 'value' : item.link}}))
if self.itemExist(item.link):
return
print 'item.link = '+item.link
res = urlparse.urlparse(item.thumb)
if len(res.query) > 0:
qs = urlparse.parse_qs(res.query)
# huihui图片ID
des = qs['id'][0]
filename = des+'.png'
destfile = 'temp/'+filename
else:
filename = item.thumb[item.thumb.rfind('/'):]
destfile = 'temp'+filename
downloadimage(item.thumb,destfile)
# prepare metadata
data = {
'name': filename,
'type': 'image/png', # mimetype
}
# read the binary file and let the XMLRPC library encode it into base64
with open(destfile, 'rb') as img:
data['bits'] = xmlrpc_client.Binary(img.read())
response = self.rpcClient.call(media.UploadFile(data))
attachment_id = response['id']
post = WordPressPost()
post.title = item.title
post.content = item.content
post.thumbnail = attachment_id
post.custom_fields = [{'key':'link_value', 'value' : item.link}]
post.id = self.rpcClient.call(posts.NewPost(post))
# # attachment_id.parentid = post.id
# # whoops, I forgot to publish it!
post.post_status = 'publish'
# cats = self.rpcClient.call(taxonomies.GetTerms('category'))
for cat in self.categorys:
if cat.name == item.category:
post.terms = [cat]
break
self.rpcClient.call(posts.EditPost(post.id, post))
示例7: upload_post
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import custom_fields [as 别名]
def upload_post(auth, **args):
wp = Client(auth['site'], auth['user'], auth['pass'])
post = WordPressPost()
post.post_type = args.get('type', None)
post.title = args.get('title', None)
post.content = args.get('content', None)
post.date = gen_datetime(args['date'], args.get('date-format', None),
args.get('zone', 0))
terms = {key: [value] for key, value in args.get('terms', {}).items()}
post.terms_names = terms
if args.get('path', None) is not None:
post.custom_fields = [{'key': 'enclosure',
'value': upload_media(args['path'], wp)
}]
if args.get('publish', False):
post.post_status = 'publish'
post.id = wp.call(posts.NewPost(post))
示例8: _post_newpost_to_wordpress
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import custom_fields [as 别名]
def _post_newpost_to_wordpress(self, item, attachment_id):
post = WordPressPost()
post.title = item['title']
post.content = item['content']
post.post_type = "post"
post.post_status = "publish"
post.terms_names = {
'post_tag': item['tags'],
'category': [item['url_from']]
}
post.custom_fields = []
post.custom_fields.append({
'key': 'custom_source_url',
'value': item['url']
})
# cat1 = self.wp.call(taxonomies.GetTerm('category', 'wanghao'))
# post.terms.append(cat1)
if attachment_id:
post.thumbnail = attachment_id
addpost = self.wp.call(posts.NewPost(post))
return addpost
示例9: create_match_post
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import custom_fields [as 别名]
def create_match_post(self, media_post, title, tags, extra):
post = WordPressPost()
post.title = title
if extra == None:
extra = ""
post.content = media_post.get_embed() + extra
post.terms_names = {
'post_tag': tags
}
post.terms = self.find_terms()
post.post_status = 'publish'
post.custom_fields = [
{
'key': 'thumbnail',
'value': media_post.get_thumb()
},
{
'key': 'event_date',
'value': self.date
}
]
post.id = self.client.call(posts.NewPost(post))
return post
示例10: open
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import custom_fields [as 别名]
'tag_list': 'list-of-tags',
'asset_data': open('audio/' + SoundCloudURL, 'rb')
})
#get the url of the uploaded SoundCloud post
SoundCloudURL = track.permalink_url
#create the wordpress post
post = WordPressPost()
post.title = 'Chapter ' + str(chapNum) + ': ' + chapTitle
HTMLtitle = '<span class="altcolor">Chapter ' + str(chapNum) + ':</span> ' + chapTitle
post.custom_fields = []
post.custom_fields.append({'key': 'HTML_title','value': HTMLtitle})
post.content = '<span class="list-text"><em><strong>Read by ' + Reader + '</strong></em>\n'
post.content = post.content + '<em>Artist: ' + Artist + '</em></span>\n'
post.content = post.content + '<!--more-->\n'
post.content = post.content + '<div id="the_player">\n'
post.content = post.content + '<strong>Read by ' + Reader + '</strong>\n'
if Recorder != 'none':
post.content = post.content + 'Introduced by Peter Donaldson and Recorded by '+Recorder+'\n'
else:
post.content = post.content + 'Introduced by Peter Donaldson <span class=\"invisRec\">Recorded by '+Recorder+'</span>\n'
post.content = post.content + '<a class="sc-player" href="'+SoundCloudURL+'">'+chapTitle+'</a>\n'
post.content = post.content + '</div>\n'
post.content = post.content + '<div class="bigborder artwork">\n'
示例11: post_article
# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import custom_fields [as 别名]
def post_article(title, content, first_img, author, source_url, source_name, delivery_url, delivery_name, class_, tmpdir):
client = Client(LF_XMLRPC_URL, LF_XMLRPC_USER, LF_XMLRPC_PASS)
retry = 5
if first_img:
logger.debug('Download image %s' % first_img)
img_path = get_img(first_img, tmpdir)
logger.debug('Download article\'s first image to %s' % img_path)
ret = None
if first_img:
for i in xrange(retry):
ret = upload_file_to_wp(client, img_path)
if ret:
break
else:
raise CanNotUploadException('xmlrpc upload %s' % img_path)
attachment_id = ret
# Download all image file, and put it into static directory in web server,
# and replace URL in the article content.
content_obj = BeautifulSoup(content)
img_tags = content_obj.find_all('img', recursive=True)
from hashlib import md5
hex_dir = md5(title.encode('utf-8')).hexdigest()
img_paths = []
img_src_list = []
for img in img_tags:
if img and img.has_attr('src'):
img_path = get_img(img.attrs['src'], tmpdir)
img_paths.append(img_path)
img_src_list.append(img.attrs['src'])
img_host_list = copy_to_web_server(img_paths, hex_dir)
if len(img_host_list) != len(img_src_list):
raise CanNotUploadException('ftp upload file length not match, local(%s), remote(%s)' % (len(img_src_list), len(img_host_list)))
for x in xrange(len(img_src_list)):
img_src_list[x] = img_host_list[x]
post = WordPressPost()
post.title = title
post.content = str(content_obj)
#post.post_status = 'publish'
if first_img:
post.thumbnail = attachment_id
post.terms_names = {
# TODO: add tags
#'post_tag': ['tagA', 'another tag'],
'category': ['公社推送', ],
}
post.custom_fields = []
post.custom_fields.append({
'key': 'source_url',
'value': source_url
})
post.custom_fields.append({
'key': 'source_name',
'value': source_name
})
post.custom_fields.append({
'key': 'delivery_name',
'value': delivery_name
})
post.custom_fields.append({
'key': 'delivery_url',
'value': delivery_url
})
post.id = client.call(posts.NewPost(post))