本文整理汇总了Python中wordpress_xmlrpc.Client类的典型用法代码示例。如果您正苦于以下问题:Python Client类的具体用法?Python Client怎么用?Python Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: 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")
开发者ID:joelewis,项目名称:QuickPress,代码行数:34,代码来源:launch.py
示例2: load_file
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)
开发者ID:Transfusion,项目名称:wp-screenshot-python,代码行数:29,代码来源:wpupload.py
示例3: upload_to_wordpress
def upload_to_wordpress(xmlrpc_url,xmlrpc_user,xmlrpc_pass,inputfile,name):
"""upload to <xmlrpc_url> as <xmlrpc_user>, <xmlrpc_pass> the <inputfile> as <name>"""
global path
metadata = {
'name': name,
'type': mimetypes.guess_type(inputfile)[0] or 'audio/mpeg',
}
try:
print xmlrpc_url,xmlrpc_user,xmlrpc_pass
wpclient = Client(xmlrpc_url,xmlrpc_user,xmlrpc_pass)
fh = open('/'.join([path,inputfile]))
# Read input file and encode as base64
with open(filename, 'rb') as fh:
data['bits'] = xmlrpc_client.Binary(fh.read())
response = wpclient.call(media.UploadFile(metadata))
# Expected response:
# response == {
# 'id': 6,
# 'name': '2013.04.28_madison_whaley.mp3',
# 'url': 'http://summitcrossing.org/wp-content/uploads/2013/04/28/2013.04.28_madison_whaley.mp3',
# 'type': 'audio/mpeg',
# }
if response['id']:
# If upload succeeded, rename input file:
os.rename(inputfile,name)
except IOError as e:
print("({})".format(e))
return response
开发者ID:roderickm,项目名称:sc3,代码行数:28,代码来源:upload_podcast_to_wordpress.py
示例4: post_article
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
开发者ID:arshiyan,项目名称:wp-xmlrpc,代码行数:30,代码来源:wp_xmplrpc.py
示例5: test_pages
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)
开发者ID:OSMBrasil,项目名称:paicemana,代码行数:7,代码来源:wordpressxmlrpc.py
示例6: __init__
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']
开发者ID:dagrha,项目名称:textual-analysis,代码行数:29,代码来源:blogpost.py
示例7: get_blog_subscribers
def get_blog_subscribers(self):
""" Gets WordPress Blog Subscribers """
config = SafeConfigParser()
config.read(os.path.join(os.path.dirname(__file__), 'config.ini'))
try:
url = config.get("wordpress", "url")
username = config.get("wordpress", "username")
password = config.get("wordpress", "password")
except Error as error:
msg = "Config section [wordpress] bad or missing: %s" % \
error.message
logging.error(msg)
raise Exception(msg)
subs = []
wp = Client(url, username, password)
users = wp.call(GetUsers())
logging.info("Found %d users." % len(users))
for u in users:
logging.debug("User: %s" % u.email)
logging.debug("Roles: %s" % u.roles)
if 'subscriber' in u.roles:
subs.append((u.email, u.first_name))
return subs
开发者ID:mrichman,项目名称:nhs-emailvision,代码行数:25,代码来源:wordpress.py
示例8: PushToWeb
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)
开发者ID:davidf-2013,项目名称:adelphi-ed-tech-courses,代码行数:27,代码来源:build.py
示例9: media_upload
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
开发者ID:andrewklau,项目名称:asc2wp-Asciidoc-to-Wordpress,代码行数:28,代码来源:asc2wp.py
示例10: _post_to_wp
def _post_to_wp(post):
# Keep 3rd party calls separate
client = Client(
url=settings.XML_RPC_URL,
username=settings.XML_RPC_USERNAME,
password=settings.XML_RPC_PW
)
return client.call(post)
开发者ID:katstevens,项目名称:jukebox-tnj,代码行数:8,代码来源:views.py
示例11: upload
def upload(pic):
(_ , ext) = os.path.splitext(pic)
wp_client = Client(rpc_service_url, user, password)
data = {'name':str(uuid4()) + ext, 'type':mimetypes.guess_type(pic)[0]}
with open(pic, 'rb') as img:
data['bits'] = xmlrpc_client.Binary(img.read())
rsp = wp_client.call(media.UploadFile(data))
return rsp
开发者ID:ZHTonyZhang,项目名称:52woo,代码行数:8,代码来源:publish.py
示例12: wp_post
def wp_post(post_type, limit):
from wordpress_xmlrpc import Client
from wordpress_xmlrpc.methods import posts
wp = Client('http://www.leedsdatamill.org/xmlrpc.php', 'USERNAME', 'PASSWORD')
published_posts = wp.call(posts.GetPosts({'post_status': 'publish', 'number': limit, 'orderby': 'post_date', 'order': 'DESC', 'post_type': post_type }))
return published_posts
开发者ID:LeedsDataMill,项目名称:Ckan,代码行数:8,代码来源:plugin.py
示例13: getWordpressPosts
def getWordpressPosts():
allPosts = []
try:
wpClient = Client(app.config.get('BLOG_URL'), app.config.get('BLOG_USER'), app.config.get('BLOG_PASSWORD'))
allPosts = wpClient.call(posts.GetPosts({'post_status': 'publish'}))
except (ServerConnectionError, InvalidCredentialsError) as e:
logging.warn(e.message)
finally:
return allPosts
开发者ID:innogames,项目名称:gamejam,代码行数:9,代码来源:news.py
示例14: PublishPipeline
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
开发者ID:sbry,项目名称:scrapy-berlin,代码行数:57,代码来源:pipelines.py
示例15: share_on_facebook
def share_on_facebook(post_ids, access_token, page_id=PAGE_ID):
graph = facebook.GraphAPI(access_token)
client = Client('http://domain.com/xmlrpc.php','username','password')
for post_id in post_ids:
post = client.call(GetPost(post_id))
link = post.link
path = '/'+str(page_id)+'/feed'
post = graph.request(path=path,post_args={'link':post.link})
print post
开发者ID:heaven00,项目名称:scraper,代码行数:9,代码来源:script.py
示例16: getWordpressPostById
def getWordpressPostById(id):
wpPost = []
try:
wpClient = Client(app.config.get('BLOG_URL'), app.config.get('BLOG_USER'), app.config.get('BLOG_PASSWORD'))
wpPost = wpClient.call(posts.GetPost(id))
except (ServerConnectionError, InvalidCredentialsError) as e:
logging.warn(e.message)
finally:
return wpPost
开发者ID:innogames,项目名称:gamejam,代码行数:9,代码来源:news.py
示例17: getWordpressCategories
def getWordpressCategories():
wpCats = []
try:
wpClient = Client(app.config.get('BLOG_URL'), app.config.get('BLOG_USER'), app.config.get('BLOG_PASSWORD'))
wpCats = wpClient.call(taxonomies.GetTerms('category'))
except (ServerConnectionError, InvalidCredentialsError) as e:
logging.warn(e.message)
finally:
return wpCats
开发者ID:innogames,项目名称:gamejam,代码行数:9,代码来源:news.py
示例18: get_categories
def get_categories(site_id):
'''
获取site_id的所有category
:param site_id:
:return:
'''
site = Site.objects.get(pk=site_id)
client = Client(site.url + '/xmlrpc.php', site.username, site.password)
categories = client.call(taxonomies.GetTerms('category'))
return categories
开发者ID:GoTop,项目名称:AutoSystem,代码行数:10,代码来源:wordpress.py
示例19: main
def main():
client = Client("http://jonathanlurie.fr/xmlrpc.php", "jonathanlurie", "jo.270185")
allPosts = client.call(posts.GetPosts())
for p in allPosts:
try:
print p
except:
None
开发者ID:jonathanlurie,项目名称:pythonStuff,代码行数:10,代码来源:wptests.py
示例20: __init__
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))
开发者ID:OSMBrasil,项目名称:paicemana,代码行数:10,代码来源:wordpressxmlrpc.py
注:本文中的wordpress_xmlrpc.Client类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论