本文整理汇总了Python中wordpress_xmlrpc.Client.call方法的典型用法代码示例。如果您正苦于以下问题:Python Client.call方法的具体用法?Python Client.call怎么用?Python Client.call使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wordpress_xmlrpc.Client
的用法示例。
在下文中一共展示了Client.call方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from wordpress_xmlrpc import Client [as 别名]
# 或者: from wordpress_xmlrpc.Client import call [as 别名]
class BlogPost:
def __init__(self,user,password):
self.wp = Client("http://dataslant.xyz/xmlrpc.php",user,password)
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))
def uploadJPG(self, filePath):
data = {
'name': filePath.split('/')[-1],
'type': 'image/jpeg',
}
with open(filePath, 'rb') as img:
data['bits'] = xmlrpc_client.Binary(img.read())
response = self.wp.call(media.UploadFile(data))
return response['id']
示例2: post_article
# 需要导入模块: from wordpress_xmlrpc import Client [as 别名]
# 或者: from wordpress_xmlrpc.Client import call [as 别名]
def post_article(self,wpUrl,wpUserName,wpPassword,articleTitle, articleCategories, articleContent, articleTags,PhotoUrl):
self.path=os.getcwd()+"\\00000001.jpg"
self.articlePhotoUrl=PhotoUrl
self.wpUrl=wpUrl
self.wpUserName=wpUserName
self.wpPassword=wpPassword
#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
示例3: media_upload
# 需要导入模块: from wordpress_xmlrpc import Client [as 别名]
# 或者: from wordpress_xmlrpc.Client import call [as 别名]
def media_upload():
print 'Media Upload'
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.compat import xmlrpc_client
from wordpress_xmlrpc.methods import media, posts
client = Client(xmlrpc_url, username, password)
if len(param_list[2:]) == 0:
print "Error: Please select Uploads file"
sys.exit(0)
else:
for f in param_list[2:]:
filepath = os.path.abspath(f)
filename = os.path.basename(filepath.strip())
dirname = os.path.dirname(filepath.strip())
# prepare metadata
data = {
'name': filename,
'type': mimetypes.guess_type(filename)[0]
}
# read the binary file and let the XMLRPC library encode it into base64
with open(filepath.strip(), 'rb') as img:
data['bits'] = xmlrpc_client.Binary(img.read())
response = client.call(media.UploadFile(data))
attachment_id = response['id']
media_info = client.call(media.GetMediaItem(attachment_id))
media_filename = os.path.basename(media_info.link.strip())
print '==========================\n' + 'Attachment ID : ' + attachment_id + '\nFile name : ' + media_filename + '\nFile url : ' + media_info.link
示例4: post
# 需要导入模块: from wordpress_xmlrpc import Client [as 别名]
# 或者: from wordpress_xmlrpc.Client import call [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: PublishPipeline
# 需要导入模块: from wordpress_xmlrpc import Client [as 别名]
# 或者: from wordpress_xmlrpc.Client import call [as 别名]
class PublishPipeline(object):
"""
use xmlprc of wordpress to synchronize via push
"""
@classmethod
def from_crawler(cls, crawler):
return cls()
def open_spider(self, spider):
self.client = Client(os.getenv('SCRAPY_WP_RPCURL'),
os.getenv('SCRAPY_WP_USERNAME'),
os.getenv('SCRAPY_WP_PASSWORD'))
pass
def close_spider(self, spider):
pass
def process_item(self, item, spider):
wp_filename = item.filename('wp')
if os.path.exists(wp_filename):
with open(wp_filename) as fh:
post = pickle.load(fh)
fh.close()
# #
# Here one might update or fix things
if False:
post.terms_names = {
'category': [item['source_name'].title()],
'post_tag': get_place_post_tag_names(item['place'])
}
self.client.call(posts.EditPost(post.id, post))
pass
pass
pass
else:
post = WordPressPost()
post.title = item['headline']
try:
post.content = item['body']
except KeyError:
return None
try:
item['place']
except KeyError:
item['place'] = ""
post.terms_names = {
'category': [item['source_name'].title()],
'post_tag': get_place_post_tag_names(item['place'])
}
post.link = item['source_url']
post.date = item['time']
post.post_status = 'publish'
post.id = self.client.call(posts.NewPost(post))
with open(wp_filename, 'wb') as fh:
pickle.dump(post, fh)
fh.close()
pass
return item
pass
pass
示例6: __init__
# 需要导入模块: from wordpress_xmlrpc import Client [as 别名]
# 或者: from wordpress_xmlrpc.Client import call [as 别名]
def __init__(self, user, password, archive, lfrom='pt', lto='pb'):
client = Client('http://www.weeklyosm.eu/xmlrpc.php', user, password)
post = client.call(posts.GetPost(archive))
tagfrom = '[:%s]' % lfrom
tagto = '[:%s]' % lto
post.title = post.title.replace(tagfrom, tagto)
post.content = post.content.replace(tagfrom, tagto)
#print(post.title)
#print(post.content)
client.call(posts.EditPost(post.id, post))
示例7: wp_truncate
# 需要导入模块: from wordpress_xmlrpc import Client [as 别名]
# 或者: from wordpress_xmlrpc.Client import call [as 别名]
def wp_truncate():
client = Client(os.getenv('SCRAPY_WP_RPCURL'),
os.getenv('SCRAPY_WP_USERNAME'),
os.getenv('SCRAPY_WP_PASSWORD'))
while 1:
posts_slice = client.call(posts.GetPosts())
if len(posts_slice):
for p in posts_slice:
client.call(posts.DeletePost(p.id))
else:
break
示例8: sourcename
# 需要导入模块: from wordpress_xmlrpc import Client [as 别名]
# 或者: from wordpress_xmlrpc.Client import call [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))
示例9: create_wordpress_draft
# 需要导入模块: from wordpress_xmlrpc import Client [as 别名]
# 或者: from wordpress_xmlrpc.Client import call [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
示例10: func_Create_WP_Post
# 需要导入模块: from wordpress_xmlrpc import Client [as 别名]
# 或者: from wordpress_xmlrpc.Client import call [as 别名]
def func_Create_WP_Post(atitle, acontent, category):
wp = Client(WPPATH, WPUSER, WPPASS)
my_category = category
post = WordPressPost()
post.title = atitle
post.content = acontent
post.post_format = "video"
post.terms_names = {'category':[my_category]}
print(category)
print("---")
my_posts = []
#my_posts = set()
my_increment = 20
my_offset = 0
while True:
wp_obj_posts = wp.call(posts.GetPosts({'number': my_increment, "offset": my_offset}))
if len(wp_obj_posts) == 0:
break
for apost in wp_obj_posts:
apost = apost.content
apost = apost.split("embed/",1)[1]
#my_posts.add(apost)
my_posts.append(apost)
#try:
# print(apost.title)
#except UnicodeEncodeError:
# print("'ascii' codec can't encode character.")
my_offset += my_increment
#print(wp_obj_posts)
#print("---")
print(my_posts)
print("---")
post_id = post.content.split("embed/",1)[1]
print(post_id)
#my_posts = sorted(my_posts)
if post_id in my_posts:
print("Dublicate post!!!\n")
print("---")
else:
print("Posted!\n")
print("---")
post.id = wp.call(posts.NewPost(post))
post.post_status = 'publish'
wp.call(posts.EditPost(post.id, post))
示例11: publish
# 需要导入模块: from wordpress_xmlrpc import Client [as 别名]
# 或者: from wordpress_xmlrpc.Client import call [as 别名]
def publish(pic, title, content):
'''
'''
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'
wp_client.call(posts.EditPost(post.id, post))
return post.id
示例12: load_file
# 需要导入模块: from wordpress_xmlrpc import Client [as 别名]
# 或者: from wordpress_xmlrpc.Client import call [as 别名]
def load_file(self):
fname = askopenfilename(filetypes=(("PNG Image", "*.png"),
("JPG Image", "*.jpg;*.jpeg"),
("GIF Image", "*.gif"),
("Bitmap Image", "*.bmp"),
("All Files", "*")))
print(mimetypes.guess_type(fname)[0])
try:
wp = Client('https://your.wordpress.installation/xmlrpc.php', 'Username', 'password')
except TimeoutError:
self.status.delete(0, END)
self.status.insert(0, 'Unable to connect to WP')
except gaierror:
self.status.config(state=NORMAL)
self.status.delete(1.0, END)
self.status.insert(1.0, 'DNS lookup failed')
self.status.config(state=DISABLED)
raise
print(MyFrame.path_leaf(fname))
data = {'name': MyFrame.path_leaf(fname), 'type': mimetypes.guess_type(fname)[0]}
with open(fname, 'rb') as img:
data['bits'] = xmlrpc_client.Binary(img.read())
response = wp.call(media.UploadFile(data))
print(response['url'])
self.status.config(state=NORMAL)
self.status.delete(1.0, END)
self.status.insert(1.0, 'Link: '+response['url'])
self.status.config(state=DISABLED)
示例13: test_pages
# 需要导入模块: from wordpress_xmlrpc import Client [as 别名]
# 或者: from wordpress_xmlrpc.Client import call [as 别名]
def test_pages(user, password):
from wordpress_xmlrpc import WordPressPage
client = Client('http://www.weeklyosm.eu/xmlrpc.php', user, password)
pages = client.call(posts.GetPosts({'post_type': 'page'}, results_class=WordPressPage))
p = pages[0]
print(p.id)
print(p.title)
示例14: PushToWeb
# 需要导入模块: from wordpress_xmlrpc import Client [as 别名]
# 或者: from wordpress_xmlrpc.Client import call [as 别名]
def PushToWeb(courses):
if not pushToWordPress:
return
client = Client(url,user,pw)
pages = GetWebPages()
for course in courses:
print("pushing to web", course)
try:
page = pages[course]
f = open("raw/%s.html" % (course,),"r")
page.content = f.read()
f.close()
except IOError as ioe:
print("** no raw file found for",course)
print(ioe)
continue
except KeyError as keyx:
print("** no course found on blog",course)
print(keyx)
continue
result = client.call(posts.EditPost(page.id, page))
if result:
print("Successfully updated ", page.slug)
else:
print("******Warning********: could not update ", page.slug)
示例15: upload
# 需要导入模块: from wordpress_xmlrpc import Client [as 别名]
# 或者: from wordpress_xmlrpc.Client import call [as 别名]
def upload(name, title):
client = Client("http://domain.com/xmlrpc.php", "username", "password")
imgfile = os.path.join(DATA_DIR, name)
# imgfile = 'op/%s'%name
data = {"name": name, "type": "image/jpg"}
with open(imgfile, "rb+") as imag:
data["bits"] = xmlrpc_client.Binary(imag.read())
response = client.call(media.UploadFile(data))
attachment_id = response["id"]
_title = lxml.html.fromstring(title).text
post = WordPressPost()
post.title = _title
post.post_status = "publish"
post.thumbnail = attachment_id
post.comment_status = "open"
post.id = client.call(posts.NewPost(post))