# -*- coding: utf-8 -*- ''' 反斗限免 1, 获取反斗限免数据 2, 储存到mongodb 3, 发送到指定邮件 ''' import re import sys import os sys.path.append(os.path.join(os.path.abspath(__file__).split('AutoInfo')[0] + 'AutoInfo')) from utils.utils import * config_json = LoadConfig().load_config() DEFAULT_RE_PUSH_TIMES = config_json['DEFAULT_RE_PUSH_TIMES'] class APPRCN(object): def __init__(self): self.logs_handle = LogsHandle() self.now_day = time.strftime('%Y-%m-%d', time.localtime()) self.base_url = 'https://free.apprcn.com/page/{}/' self.headers = { 'User-Agent': 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; Media Center PC 6.0; InfoPath.2; MS-RTC LM 8' } db = 'NEWS' collection = 'apprcn-info' self.mongo = MongoHandle(db=db, collection=collection, del_db=False, del_collection=False, auto_remove=0) self.temp_datas = [] def main(self): self.logs_handle.logs_write('apprcn', '开始获取反斗限免数据', 'start', False) response_data = self.req() if response_data: self.save_to_mongo(response_data) self.send_to_gotify() self.logs_handle.logs_write('apprcn', '反斗限免数据获取完成', 'done', False) print('done') else: self.logs_handle.logs_write('apprcn', '无法获取apprcn数据', 'error', False) def req(self): urls = ['https://free.apprcn.com/'] for i in range(2, 10): urls.append(self.base_url.format(i)) response_data = [] for i in urls: response = httpx.get(url=i, headers=self.headers) if response.status_code != 200: self.logs_handle.logs_write('apprcn', '请求失败, 状态码: %s' % response.status_code, 'error', False) exit(0) response.encoding = 'utf-8' content_list = re.findall('