当前位置: 首页>>代码示例>>Python>>正文


Python WordPressPost.thumbnail方法代码示例

本文整理汇总了Python中wordpress_xmlrpc.WordPressPost.thumbnail方法的典型用法代码示例。如果您正苦于以下问题:Python WordPressPost.thumbnail方法的具体用法?Python WordPressPost.thumbnail怎么用?Python WordPressPost.thumbnail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wordpress_xmlrpc.WordPressPost的用法示例。


在下文中一共展示了WordPressPost.thumbnail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post_article

# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import thumbnail [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
开发者ID:arshiyan,项目名称:wp-xmlrpc,代码行数:32,代码来源:wp_xmplrpc.py

示例2: post

# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import thumbnail [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))
开发者ID:sugarsweetrobotics,项目名称:wordpress_plugin,代码行数:48,代码来源:__init__.py

示例3: sourcename

# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import thumbnail [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))
开发者ID:trujunzhang,项目名称:djzhang-targets,代码行数:55,代码来源:sample_code.py

示例4: process_item

# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import thumbnail [as 别名]
 def process_item(self, item, spider):
     post = WordPressPost()
     post.title = item['title']
     post.content = item['content'] + settings.get('GOTO_SOURCE', "[%s]") % item['link']
     post.date = datetime.datetime.strptime(item['publish_date'],
                                         "%Y-%m-%d %H:%M")
     post.terms_names = {
         'post_tag': item['tag'],
         'category': item['category'] if len(item['category']) > 0 else ['gist'],
     }
     post.post_status = 'publish'
     post.thumbnail = self.create_thumbnail(item)
     post.id = self.client.call(posts.NewPost(post))
     return item
开发者ID:zhanghui9700,项目名称:spider.appcheckin.com,代码行数:16,代码来源:pipelines.py

示例5: addItem

# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import thumbnail [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))
开发者ID:sunyifei83,项目名称:python-py,代码行数:50,代码来源:test_wanbin.py

示例6: post_picture

# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import thumbnail [as 别名]
def post_picture(image_url):
    fileImg = urlopen(image_url)
    imageName = fileImg.url.split('/')[-1]+'.jpg'
    data = {
        'name': imageName,
        'type': 'image/jpeg',
    }
    data['bits'] = xmlrpc_client.Binary(fileImg.read())

    response = client.call(media.UploadFile(data))
    attachment_id = response['id']
    post = WordPressPost()
    post.title = 'Picture of the Day'
    post.post_status = 'publish'
    post.thumbnail = attachment_id
    post.id = client.call(posts.NewPost(post))
开发者ID:githubsec,项目名称:autopost,代码行数:18,代码来源:onePicture.py

示例7: publish

# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import thumbnail [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
开发者ID:ccfruit,项目名称:52woo,代码行数:18,代码来源:autopublish.py

示例8: upload

# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import thumbnail [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))
开发者ID:heaven00,项目名称:python-script-Scraper,代码行数:18,代码来源:9gag_scraper.py

示例9: upload_article

# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import thumbnail [as 别名]
    def upload_article(self, article, img_url, tags, categories):
        """
        Create a post object, initialize its properties and upload it.
        :param article: HTML string
        :param img_url: the url to img
        :param tags: list with tags
        :param categories: list with categories
        """
        post = WordPressPost()
        post.title = self.title
        post.content = article
        post.thumbnail = self._upload_image(img_url)
        post.terms_names = {'post_tag': tags,
                            'category': categories}

        # post.post_status = 'publish'
        post.id = self.client.call(NewPost(post))
开发者ID:netarachelhershko,项目名称:amazon_aotumation,代码行数:19,代码来源:wordpress_uploader.py

示例10: post_to_wordpress

# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import thumbnail [as 别名]
    def post_to_wordpress(
        self,
        title,
        content,
        detail_url,
        image_upload_id,
        retry,
        ):
        
        # now post the post and the image
        post = WordPressPost()
        post.post_type = 'portfolio'
        post.title = title
        post.content = content
        post.post_status = 'publish'
        post.thumbnail = image_upload_id

        if self.wp.call(NewPost(post)):
            return True
开发者ID:basilleaf,项目名称:marsfromspace,代码行数:21,代码来源:publish.py

示例11: post_data_to_site

# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import thumbnail [as 别名]
def post_data_to_site(titles, filenames):
	post_ids = []
	client = Client('http://domain.com/xmlrpc.php','username','password')
	for i in range(0,len(titles)):
		post_title, filename = titles[i], filenames[i]
		imgfile = os.path.join(DATA_DIR, filename)
		data = {'name':filename, 'type':'image/jpg'}
		with open(imgfile, 'rb+') as img:
			data['bits'] = xmlrpc_client.Binary(img.read())
		response = client.call(media.UploadFile(data))
		attachment_id = response['id']
		post = WordPressPost()
		post.title = post_title
		post.post_status = 'publish'
		post.thumbnail = attachment_id
		post.comment_status = 'open'
		post.id = client.call(posts.NewPost(post))
		post_ids.append(post.id)
		print post.id
	return post_ids	
开发者ID:heaven00,项目名称:scraper,代码行数:22,代码来源:script.py

示例12: publish

# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import thumbnail [as 别名]
def publish(pic, title, content):
    '''
    publish a post and set to open to comment and ping(trackback)
    '''
    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'
    post.comment_status = 'open'
    post.ping_status = 'open'
    post.user = account_ids[r.randint(0, len(account_ids)-1)]
    wp_client.call(posts.EditPost(post.id, post))
    return post.id
开发者ID:ZHTonyZhang,项目名称:52woo,代码行数:22,代码来源:publish.py

示例13: addItemsToWordpress

# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import thumbnail [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))
开发者ID:a-castellano,项目名称:NewsScrapper,代码行数:41,代码来源:scrapper.py

示例14: wordpress_post

# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import thumbnail [as 别名]
def wordpress_post(config):
    print("Connecting to: " + config.wordpress['xmlrpc'])
    wp = Client(config.wordpress['xmlrpc'],
                config.wordpress['username'],
                config.wordpress['password'])

    if config.attach_header:
        print("Uploading header image...")
        # Upload header image
        data = {
            'name': os.path.basename(config.png_header_file),
            'type': 'image/png',
        }

        # Read the image and let the XMLRPC library encode it to base64
        with open(config.png_header_file, 'rb') as img:
            data['bits'] = xmlrpc_client.Binary(img.read())

        response = wp.call(media.UploadFile(data))
        attachment_id = response['id']

    print("Posting blog...")
    post = WordPressPost()
    post.title = config.wordpress['title']
    post.content = config.wordpress['content']
    post.post_format = config.wordpress['post_format']
    post.post_status = config.wordpress['post_status']
    post.comment_status = config.wordpress['comment_status']
    if config.attach_header:
        post.thumbnail = attachment_id
    post.terms_names = {
        'post_tag': [config.wordpress['tags']],
        'category': [config.wordpress['category']]
    }
    post.id = wp.call(NewPost(post))

    if config.wordpress['podcast_plugin'] == 'Powerpress':
        get_audio_size_and_duration(config)
开发者ID:rikai,项目名称:podpublish,代码行数:40,代码来源:uploader.py

示例15: add_or_edit_wp_post

# 需要导入模块: from wordpress_xmlrpc import WordPressPost [as 别名]
# 或者: from wordpress_xmlrpc.WordPressPost import thumbnail [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)
开发者ID:JeffAMcGee,项目名称:exofranck,代码行数:40,代码来源:wp_post.py


注:本文中的wordpress_xmlrpc.WordPressPost.thumbnail方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。