コード例 #1
0
ファイル: base.py プロジェクト: ddkangfu/RedKindle
	def Items(self,opts=None):
		"""
		生成器,返回一个元组
		对于HTML:section,url,title,content,brief
		对于图片,mime,url,filename,content,brief
		"""
		urls = self.ParseFeedUrls()
		readability = self.readability if self.fulltext_by_readability else self.readability_by_soup
		prevsection = ''
		decoder = AutoDecoder(False)
		for section,ftitle,url,desc in urls:
			if not desc:#非全文
				if section != prevsection or prevsection == '':
					decoder.encoding = ''
					prevsection = section
				article = self.fetcharticle(url,decoder)
				if not article:
					continue
			else:
				article = self.FragToXhtml(desc,ftitle)
			#如果是图片,title则是mime
			for title, imgurl, imgfn, content, brief in readability(article,url,opts):
				if title.startswith(r'image/'): #图片
					try:
						content = rescale_image(content,reduceto=(400,600),graying=False)
					except:
						content = content
					yield (title, imgurl, imgfn, content, brief)
				else:
					if not title: title = ftitle
					content =  self.postprocess(content)
					yield (section, url, title, content, brief)
コード例 #2
0
    def Items(self, opts=None):
        """
		生成器,返回一个元组
		对于HTML:section,url,title,content,brief
		对于图片,mime,url,filename,content,brief
		"""
        urls = self.ParseFeedUrls()
        readability = self.readability if self.fulltext_by_readability else self.readability_by_soup
        prevsection = ''
        decoder = AutoDecoder(False)
        for section, ftitle, url, desc in urls:
            if not desc:  #非全文
                if section != prevsection or prevsection == '':
                    decoder.encoding = ''
                    prevsection = section
                article = self.fetcharticle(url, decoder)
                if not article:
                    continue
            else:
                article = self.FragToXhtml(desc, ftitle)
            #如果是图片,title则是mime
            for title, imgurl, imgfn, content, brief in readability(
                    article, url, opts):
                if title.startswith(r'image/'):  #图片
                    try:
                        content = rescale_image(content,
                                                reduceto=(400, 600),
                                                graying=False)
                    except:
                        content = content
                    yield (title, imgurl, imgfn, content, brief)
                else:
                    if not title: title = ftitle
                    content = self.postprocess(content)
                    yield (section, url, title, content, brief)
コード例 #3
0
ファイル: base.py プロジェクト: ddkangfu/RedKindle
	def process_image(self,data,opts):
		try:
			if not opts or not opts.process_images or not opts.process_images_immediately:
				return data
			elif opts.mobi_keep_original_images:
				return mobify_image(data)
			else:
				return rescale_image(data, png2jpg=opts.image_png_to_jpg,
						graying=opts.graying_image,
						reduceto=opts.reduce_image_to)
		except Exception:
			return None
コード例 #4
0
 def process_image(self, data, opts):
     try:
         if not opts or not opts.process_images or not opts.process_images_immediately:
             return data
         elif opts.mobi_keep_original_images:
             return mobify_image(data)
         else:
             return rescale_image(data,
                                  png2jpg=opts.image_png_to_jpg,
                                  graying=opts.graying_image,
                                  reduceto=opts.reduce_image_to)
     except Exception:
         return None
コード例 #5
0
ファイル: test.py プロジェクト: wyntung/RedKindle
from lib.img import rescale_image
from lib.url_req import URLOpener
import os

#rescale_image(data, maxsizeb=4000000, dimen=None, png2jpg=False,     graying=True, reduceto=(600,800)):


test = URLOpener().open('http://img.xinjunshi.com/uploads/allimg/140224/11-140224101225.jpg')
#test=URLOpener().open('http://www.sucaitianxia.com/d/file/20131222/28caa29d1ddad3c085035e024a9f0b02.png')
con = test.content

con = rescale_image(con,reduceto=(400,600),graying=False)
fout = open('zzh.jpg', "wb")
fout.write(con)
fout.close()