Exemplo n.º 1
0
class MyImagesPipeline(ImagesPipeline):
    def __init__(self, store_uri, download_func=None, settings=None):
        super(MyImagesPipeline, self).__init__(store_uri,
                                               download_func=None,
                                               settings=None)
        botName = 'weixin'  # 注意需要更改。。。
        self.fileUtil = UploadUtil(u'/news/' + botName + u'/image/', u'img/')

    def get_media_requests(self, item, info):
        for image_url in item['image_urls']:
            yield Request(image_url['url'])

    def item_completed(self, results, item, info):
        # [{path:'', url:''}]
        for ok, x in results:
            if ok:
                url = x['url']
                path = x['path']
                imgUrl = self.fileUtil.upload(path)
                if imgUrl:
                    # 拿出内容,然后替换路径为url
                    item['content_html'] = item['content_html'].replace(
                        '&',
                        '&').replace(url, imgUrl).replace('data-src', 'src')
        return item
Exemplo n.º 2
0
 def __init__(self, botName, savePath):
     self.botName = botName
     self.savePath = savePath
     self.fileUtil = UploadUtil(u'/news/' + botName + u'/image/', u'img/')
Exemplo n.º 3
0
 def __init__(self, store_uri, download_func=None, settings=None):
     super(MyImagesPipeline, self).__init__(store_uri,
                                            download_func=None,
                                            settings=None)
     botName = 'sina'  # 注意需要更改。。。
     self.fileUtil = UploadUtil(u'/news/' + botName + u'/image/', u'img/')
Exemplo n.º 4
0
# -*- coding: utf-8 -*-

from libMe.util.FileUtil import UploadUtil
fileUtil = UploadUtil(u'/news/wangyi/image/', u'../../res/img/wangyi/')
fileUtil.upload([{
    "path": 'full/391ae6114d37f3a54f369c65d782a2588e625f13.jpg'
}])