def firefox_ver(self, value): # 如果格式不符合,保持原来的值,不做任何修改 if not helper.match_expect_type(value, 'dict'): return if 'min' in value and helper.match_expect_type(value['min'], 'int'): self._firefox_ver['min'] = value['min'] # 使用range进行list生成时,会会忽略最大值,所以需要+1 # [range(74, 75)] => [74] if 'max' in value and helper.match_expect_type(value['max'], 'int'): self._firefox_ver['max'] = value['max'] + 1
def chrome_max_release_year(self, value): # 是否为整数 if not helper.match_expect_type(value, 'int'): return # 是否大于0 if value < 0: return # 是否小于当前年-2008 if CHROME_MAX_RELEASE_YEAR < value: return self._chrome_max_release_year = value
def site_max_page_no(self, value): if not gbh_helper.match_expect_type(value, 'int'): raise ValueError('site_max_page_no的值必须是整数') if value < 1 or value > 10: raise ValueError('site_max_page_no的值必须在1到9之间') # 实际使用列表表达式生成url,因此site_max_page_no要+1,符合感受 self._site_max_page_no = value + 1 self._site = self._generate_site( enumset_site=self._raw_site, enumset_protocol=self._protocol, int_site_max_page_no=self._site_max_page_no)
def time_interval_in_seconds(self, old_date_time, new_date_time): ''' 计算old_date_time和new_date_time之间时间间隔,单位秒 :param old_date_time: :param new_date_time: :return: int ''' if not helper.match_expect_type(old_date_time, 'datetime.datetime'): if helper.match_expect_type(old_date_time, 'str'): old_date_time = datetime.datetime.strptime( old_date_time, '%Y-%m-%d %H:%M:%S') else: raise ValueError('old_date_time的格式不正确') if not helper.match_expect_type(new_date_time, 'datetime.datetime'): if helper.match_expect_type(new_date_time, 'str'): new_date_time = datetime.datetime.strptime( new_date_time, '%Y-%m-%d %H:%M:%S') else: raise ValueError('new_date_time的格式不正确') # datetime.datetime.now()+datetime.timedelta(days=1) return int((new_date_time - old_date_time).total_seconds())
def getExtractDataFunction(webenum): ''' 根据enum SupportedWeb的名字,返回对应的prefilter函数,如果没有出错,返回None :param webenum: :return: function ''' if not gbh_helper.match_expect_type(webenum, 'SupportedWeb'): return if webenum.name == gfp_self_enum.SupportedWeb.Xici.name: return gen_proxy_from_page.extra_data_from_page_xicidaili if webenum.name == gfp_self_enum.SupportedWeb.Kuai.name: return gen_proxy_from_page.extra_data_from_page_kuaidaili if webenum.name == gfp_self_enum.SupportedWeb.Proxylist.name: return gen_proxy_from_page.extra_data_from_page_proxylist if webenum.name == gfp_self_enum.SupportedWeb.Hidemy.name: return gen_proxy_from_page.extra_data_from_page_hidemy return
def getPrefilterFunction(webenum): ''' 根据enum SupportedWeb的名字,返回对应的prefilter函数,如果没有出错,返回None :param webenum: :return: function ''' if not gbh_helper.match_expect_type(webenum, 'SupportedWeb'): return if webenum.name == gfp_self_enum.SupportedWeb.Xici.name: return prefilter.pre_filter_xicidaili if webenum.name == gfp_self_enum.SupportedWeb.Kuai.name: return prefilter.pre_filter_kuaidaili if webenum.name == gfp_self_enum.SupportedWeb.Proxylist.name: return prefilter.pre_filter_proxy_list if webenum.name == gfp_self_enum.SupportedWeb.Hidemy.name: return prefilter.pre_filter_hidemy return
def valid_time_in_db(self, value): if not gbh_helper.match_expect_type(value, 'int'): raise ValueError('valid_time_in_db的值必须是整数') if value < 300 or value > 86400 * 5: raise ValueError('valid_time_in_db的值必须在300到86400×5之间') self._valid_time_in_db = value