示例#1
0
def new_post():
    user = current_user
    client = check_login(user.wp_url, user.wp_username, login_session['pw'])
    if request.method == 'POST':
        new_wp_post = WordPressPost()
        new_wp_post.title = request.form['title']
        new_wp_post.content = request.form['content']
        new_wp_post.status = 'publish'
        new_wp_post.id = client.call(posts.NewPost(new_wp_post))
        flash('New post successfully added')
        return redirect(url_for('get_posts'))
    else:
        return render_template('posts/newpost.html')
示例#2
0
def edit_post(wp_post_id):
    user = current_user
    client = check_login(user.wp_url, user.wp_username, login_session['pw'])
    if request.method == 'POST':
        edit_wp_post = WordPressPost()
        edit_wp_post.title = request.form['title']
        edit_wp_post.content = request.form['content']
        edit_wp_post.id = wp_post_id
        edit_wp_post.status = 'publish'
        client.call(posts.EditPost(edit_wp_post.id, edit_wp_post))
        flash('Post edited successfully')
        return redirect(url_for('get_posts'))
    else:
        return render_template('posts/editpost.html', wp_post_id=wp_post_id)
示例#3
0
def post_wordpress(loginid, loginpw, domain, title, content, post_tag,
                   category, post_status):
    """Word Pressへの簡易投稿

    Args:
        loginid (str): Your login ID.
        loginpw (str): Your login PassWord.
        domain (str): Your WordPress domain name.
        title (str): Post title.
        content (str): Post contents.
        post_tag (str[]): Post tag.
        category (str[]): Post category.
        post_status (str): Post status.

    Returns:
        None

    """

    url = "http://" + domain + "/xmlrpc.php"

    try:
        wp = Client('%s/xmlrpc.php' % url, loginid, loginpw)
    except ServerConnectionError:
        sys.exit("Cannot Connect to the server. Please check your network.")
    except:
        sys.exit("Cannot find configuration!")

    post = WordPressPost()
    post.title = title
    post.content = content
    post.terms_names = {"post_tag": post_tag, "category": category}
    post.status = post_status

    try:
        wp.call(NewPost(post))
    except InvalidCredentialsError:
        sys.exit("Username or Password is incorrect")
    except XmlrpcDisabledError:
        sys.exit("XML-RPC services are disabled in WordPress")

    print("Finish post!")
示例#4
0
    def publish(self, title, content, image_url, keywords):

        try:
            post = WordPressPost()
            post.title = title
            post.comment_status = 'approve'
            post.content = content
            post.status = 'draft'
            attachment_id = self.upload_pic(image_url)
            post.thumbnail = attachment_id
            post.terms_names = {
                'post_tag': keywords,
                'category': ['To review']
            }
            self.client.call(NewPost(post))
        except Exception as e:
            print(
                'Some errors trying to publish to Wordpress (Wordpress.py): ' +
                str(e))
            return False
        return True
				with open(filename, 'rb') as img:
					data['bits'] = xmlrpc_client.Binary(img.read())
				# load file into wordpress
				response = wordpress.call(media.UploadFile(data))
				# substitute picture placeholders in content with WP loaded URL
				if response['url'] is not None:
					parsed_url = urlparse.urlparse(response['url'])
					html_img='<a href=' + response['url'] + ' target=_blank><img class=aligncenter src=' + response['url'] + ' /></a>'
					content = content.replace('[IMG' + str(filecount) + ']', html_img)
			else:
				print "DBG File '" + filename +"' cannot be found."
				sys.exit(1)

	# assemble post object (as draft first)
	new_post = WordPressPost()
	new_post.status = 'draft'
	new_post.title = title
	new_post.content = content
	new_post.comment_status = 'open'
	new_post.ping_status = 'open'

	if post_date is not None and len(post_date.strip()) > 0:
		 #new_post.date = dateutil.parser.parse(post_date + " " + datetime.now(tzlocal()).tzname())
		new_post.date = dateutil.parser.parse(post_date)

	# categorise post
	if categories is not None and len(categories.strip()) > 0:
		for category in categories.split(','):
			category_objects = wordpress.call(taxonomies.GetTerms('category', {'search': category, 'orderby': 'count', 'number': 1}))
			if category_objects != None:
				for category_object in category_objects: