Example #1
0
 def getReCatchList(self, pageIndex):
     try:
         existStatus = [
             self.Status_save_success, self.Status_no_source,
             self.Status_dont_need_parse, self.Status_no_complete_data,
             self.Status_no_parse_method, self.Status_be_forbid
         ]
         results = self.Table.select().where(~(self.Table.status << existStatus))\
             .order_by(self.Table.haoyaoshi_id.asc())\
             .paginate(pageIndex, 15)
         return results
     except Exception as e:
         print str(e)
         LogDao.warn(str(e), belong_to='getReCatchList')
         return []
Example #2
0
 def needCatch(self, haoyaoshiId):
     try:
         existStatus = [
             self.Status_save_success, self.Status_no_source,
             self.Status_dont_need_parse, self.Status_no_complete_data,
             self.Status_no_parse_method, self.Status_be_forbid
         ]
         count = self.Table.select()\
             .where(self.Table.haoyaoshi_id == haoyaoshiId, ~(self.Table.status << existStatus))\
             .count()
         return count
     except Exception as e:
         print str(e)
         LogDao.warn(str(e), belong_to='needCatch')
         return False
Example #3
0
    def resizeImg(self, **args):
        try:
            args_key = {'ori_img': '', 'dst_img': '', 'dst_w': '', 'dst_h': '', 'save_q': 100}
            arg = {}
            for key in args_key:
                if key in args:
                    arg[key] = args[key]

            im = image.open(arg['ori_img'])
            if im.format in ['gif', 'GIF', 'Gif']:
                return
            ori_w, ori_h = im.size
            widthRatio = heightRatio = None
            ratio = 1
            if (ori_w and ori_w > arg['dst_w']) or (ori_h and ori_h > arg['dst_h']):
                if arg['dst_w'] and ori_w > arg['dst_w']:
                    widthRatio = float(arg['dst_w']) / ori_w  # 正确获取小数的方式
                if arg['dst_h'] and ori_h > arg['dst_h']:
                    heightRatio = float(arg['dst_h']) / ori_h

                if widthRatio and heightRatio:
                    if widthRatio < heightRatio:
                        ratio = widthRatio
                    else:
                        ratio = heightRatio

                if widthRatio and not heightRatio:
                    ratio = widthRatio
                if heightRatio and not widthRatio:
                    ratio = heightRatio

                newWidth = int(ori_w * ratio)
                newHeight = int(ori_h * ratio)
            else:
                newWidth = ori_w
                newHeight = ori_h

            if len(im.split()) == 4:
                # prevent IOError: cannot write mode RGBA as BMP
                r, g, b, a = im.split()
                im = image.merge("RGB", (r, g, b))

            im.resize((newWidth, newHeight), image.ANTIALIAS).save(arg['dst_img'], quality=arg['save_q'])

        except Exception as e:
            LogDao.warn(u'压缩失败' + str(e), belong_to='resizeImg')
            pass
 def updateStatus(self, name, status):
     """
     存在更改,不存在则新增
     :param status: start_request, save_success, save_fail, 404, no_complete_data, no_parse_method, dont_need_parse
     :return:
     """
     pass
     try:
         results = self.Table.select().where(self.Table.name == name)
         if len(results):
             for result in results:
                 result.status = status
                 result.update_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
                 result.save()
     except Exception as e:
         print str(e)
         LogDao.warn(str(e), belong_to='updateStatus')
Example #5
0
 def getMinStartId(self):
     try:
         existStatus = [
             self.Status_save_success, self.Status_no_source,
             self.Status_dont_need_parse, self.Status_no_complete_data,
             self.Status_no_parse_method, self.Status_be_forbid
         ]
         results = self.Table.select().where(
             ~(self.Table.status << existStatus)).order_by(
                 self.Table.haoyaoshi_id.asc())
         if len(results):
             return results[0].haoyaoshi_id
         else:
             return -1
     except Exception as e:
         print str(e)
         LogDao.warn(str(e), belong_to='getMinStartId')
         return -1
Example #6
0
 def updateStatus(self, haoyaoshiId, status):
     """
     存在更改,不存在则新增
     :param status: be_forbid, start_request, save_success, save_fail, 404, no_complete_data, no_parse_method, dont_need_parse
     :return:
     """
     pass
     try:
         results = self.Table.select().where(
             self.Table.haoyaoshi_id == haoyaoshiId)
         if len(results):
             for result in results:
                 result.status = status
                 result.save()
         else:
             table = getTableByName('haoyaoshi_status')
             table.create(haoyaoshi_id=haoyaoshiId,
                          status=status,
                          update_time=datetime.datetime.now().strftime(
                              '%Y-%m-%d %H:%M:%S'))
     except Exception as e:
         print str(e)
         LogDao.warn(str(e), belong_to='updateStatus')
Example #7
0
 def logWarn(self, msg, belong_to='', saveInDB=True):
     belong_to = belong_to or self.belong_to
     LogDao.warn(msg, belong_to=belong_to, saveInDB=saveInDB)
Example #8
0
 def logInfo(self, msg, belong_to='', saveInDB=False):
     belong_to = belong_to or self.belong_to
     LogDao.info(msg, belong_to=belong_to, saveInDB=saveInDB)
Example #9
0
 def logWarn(self, msg, belong_to='', saveInDB=False):
     belong_to = belong_to or self.name
     LogDao.warn(msg, belong_to=belong_to, saveInDB=saveInDB)