def subscribe_by_region_id(regionCode, linkmanId=8350927, username=None): """ 根据区域id依次订阅该区域内的所有医院 :param username: 根据用户名来更新 linkmanId :param regionCode: 区域编号 :param linkmanId: 订阅的用户的编号 :return: 订阅成功的数量 """ if username is not None: linkmanId = get_linkmanId_by_name(username) if linkmanId is None: print('[error]: 输入的用户名 {} 没有在系统中注册'.format(username)) return 0 departments = get_all_departments(regionCode) count = 0 for department in departments: departmentCode = department['code'] depaVaccId = department['depaVaccId'] vaccineCode = department['vaccineCode'] flag, registerDetailId = subscribe(depaCode=departmentCode, depaVaccId=depaVaccId, vaccineCode=vaccineCode, linkmanId=linkmanId) if flag: count += 1 return count
def order_by_name(self, departmentName): """ 通过社区医院名称来预约 :param departmentName: :return: """ if cfg.customId not in cfg.VACCINDE_INFO: print('[error]: 配置文件中疫苗的规格“customId”配置有误,需要从{}中选择'.format( cfg.VACCINDE_INFO.keys())) print(cfg.VACCINDE_INFO) exit() print('#' * 50) print('#' * 20 + ' 抢苗信息 ' + '#' * 20) print('抢苗用户:{}'.format(cfg.username)) print("抢苗规格:{}".format(cfg.VACCINDE_INFO[cfg.customId])) print("抢苗的社区医院:{}".format(departmentName)) print('#' * 50) print() print('开始搜索抢苗...') departments = get_department_by_name(name=departmentName) if len(departments) == 0: print('[error]: 您输入的社区名字"{}"暂时没有找到...'.format(departmentName)) exit() print('[info]: 一共查找到{}个与"{}"相关的社区医院'.format(len(departments), departmentName)) linkmanId = get_linkmanId_by_name(cfg.username) if linkmanId is None: print('[error]: 输入的用户名 {} 没有在系统中注册'.format(cfg.username)) return 0 while True: for department in departments: print() print('[info]: 处理{}社区医院...'.format(department['name'])) departmentCode = department['code'] departmentVaccineId = department['depaVaccId'] result = order_immediately( departmentCode=departmentCode, departmentVaccineId=departmentVaccineId, linkmanId=linkmanId) # print('re:', result) if result is None: print('预约失败...') else: print('预约成功') return True time.sleep(5)
def ubscribe_by_province(province): """ 根据省的名字订阅全省可订阅的社区医院 :param province: 省名字 :return: count,成功订阅的数量 """ p_json = osp.join(cfg.save_city_code_root, province + '.json') if not osp.exists(p_json): if osp.exists(osp.join(cfg.save_city_code_root, 'provinces.json')): f = open(osp.join(cfg.save_city_code_root, 'provinces.json'), encoding='utf-8') provinces = json.load(f) f.close() if province not in provinces.keys(): print('[error]: 你输入的省份"{}"不在已知的所有省份 {} 中'.format( province, provinces.keys())) return else: save_all_city_info() if not osp.exists(p_json): provinces = os.listdir(cfg.save_city_code_root) provinces = [p.split('.')[0] for p in provinces] provinces.remove('provinces') print('[error]: 你输入的省份"{}"不在已知的所有省份 {} 中'.format(province, provinces)) return count = 0 linkmanId = get_linkmanId_by_name(cfg.username) if linkmanId is None: print('[error]: 配置文件 config.py 中输入的用户名(username) {} 没有在系统中注册'.format( cfg.username)) return with open(p_json, encoding='utf-8') as f: cities = json.load(f) for city in cities: if 'area' not in cities[city]: print("[info]: 处理直辖市{}的{}".format(province, city)) regionCode = cities[city] count += subscribe_by_region_id(regionCode=regionCode, linkmanId=linkmanId) else: print('[info]: 处理城市:{}...'.format(city)) areas = cities[city]['area'] for area in areas: print('\t[info]: 处理 {} 的 {}...'.format(city, area)) regionCode = areas[area] count += subscribe_by_region_id(regionCode=regionCode, linkmanId=linkmanId) print('[info]: 一共成功订阅 {} 个社区医院'.format(count)) return count
def subscribe_by_name(self, name): count = 0 linkmanId = get_linkmanId_by_name(cfg.username) departments = get_department_by_name(name=name) for department in departments: departmentCode = department['code'] depaVaccId = department['depaVaccId'] vaccineCode = department['vaccineCode'] flag, registerDetailId = subscribe(depaCode=departmentCode, depaVaccId=depaVaccId, vaccineCode=vaccineCode, linkmanId=linkmanId) if flag: count += 1 print('[info]: 一共订阅了{}个社区医院'.format(count))
def subscribe_by_region_id(self, region_id): linkmanId = get_linkmanId_by_name(cfg.username) subscribe_by_region_id(regionCode=region_id, linkmanId=linkmanId)
def find_is_order(self, province=None, regionCode=None): """ 通过省份来查找是否有可预约的社区信息。一直循环查找,比如: 当该省份的所有社区医院都查询一遍之后还没有可预约的社区,则继续重复再一次查找一遍该省份的所有社区; 这样一直循环下去,直到有一个社区可以预约为止。 :param province: 省份名称 :param regionCode: 查询的区域id;如果该区域id不为空,则直接使用这个区域id来查询,跳过省份信息 :return: """ if province is None and regionCode is None: print('请输入省份或者区域id') exit() if cfg.customId not in cfg.VACCINDE_INFO: print('[error]: 配置文件中疫苗的规格“customId”配置有误,需要从{}中选择'.format( cfg.VACCINDE_INFO.keys())) print(cfg.VACCINDE_INFO) exit() print('#' * 50) print('#' * 20 + ' 抢苗信息 ' + '#' * 20) print('抢苗用户:{}'.format(cfg.username)) print("抢苗规格:{}".format(cfg.VACCINDE_INFO[cfg.customId])) if regionCode is None: regionCode = get_province_code(province=province) print("抢苗的省份:{}".format(province)) else: print("抢苗的区域id为:{}".format(regionCode)) print('#' * 50) print() print('开始搜索抢苗...') linkmanId = get_linkmanId_by_name(cfg.username) if linkmanId is None: print('[error]: 输入的用户名 {} 没有在系统中注册'.format(cfg.username)) return False success = "" index = 1 while True: time_start = time.time() # 一遍又一遍的首先查找区域所有的医院,然后再遍历每一个医院开始预约 departments = get_all_departments(regionCode=regionCode) if len(departments) == 0: print('[error]: 您输入的省份"{}"暂时没有找到存在的社区医院...'.format(province)) exit() print('第{}次轮询查找:'.format(index)) print('[info]: 在{}中一共查找到{}个社区医院'.format(province, len(departments))) can_order = [] for department in departments: departmentCode = department['code'] departmentVaccineId = department['depaVaccId'] name = department['name'] print() print('[info]: 查询"{}"社区信息'.format(name)) result = check_order_number( departmentCode=departmentCode, departmentVaccineId=departmentVaccineId, linkmanId=linkmanId) # print('re:', result) if result is None or result == 0: print('"{}"社区医院可预约人数为0...'.format(name)) else: print('"{}"社区医院可以预约'.format(name)) content = str(department) + '\n' + str(result) can_order.append(content) send_email(content, subject="约苗疫苗可预约") # return True time.sleep(5) if len(can_order) > 0: print('[info]: 一共有{}个社区医院可以预约'.format(len(can_order))) send_email(',\n'.join(can_order), subject="约苗疫苗可预约") return True time_end = time.time() print('[info]: 第{}轮查找耗时{}\n\n'.format(index, time_end - time_start)) index += 1
def order_immediately(departmentCode, departmentVaccineId, linkmanId=8350927, username=None): """ 某一个医院界面内点击立即预约按钮 请求参数组成:depaCode=4201020003&vaccineCode=8803&id=3680 :param username: 开始预约的用户名字,当该字段不为空时,它将覆盖传入的 linkmanId 参数 :param departmentCode: 部门编码,组成:区号+区内部号 :param departmentVaccineId: 部门疫苗id,也就是选择请求某一个医院的唯一标识。注意:虽然可能是同一个社区名字,但是预约的价数不一样,则对应的 departmentVaccineId 也不一样 :param linkmanId: 用户编号 :return: 返回请求的返回结果: 预约成功,返回:get_my_order_info_by_subscribeId 函数返回的结果,即预约成功的详细信息 预约失败,返回 None """ ##################################################################### # 如果用户名不为空,根据传入的用户名来获取 linkmanId if username is not None: linkmanId = get_linkmanId_by_name(username) if linkmanId is None: print('[error]: 输入的用户名 {} 没有在系统中注册'.format(username)) return 0 ##################################################################### ##################################################################### # 根据社区疫苗编号获取该社区的信息,从而获取到该社区是预约哪一价的疫苗,机获取疫苗编号 vaccineCode response = get_department_vaccine_info(depaVaccId=departmentVaccineId) if response is None: return if not response['ok']: print('[error]: 没有找到该社区的信息... , {}'.format(response['msg'])) return departmentName = response['data']['departmentName'] vaccineCode = response['data']['vaccineCode'] ##################################################################### ##################################################################### # 第一步,判断是否可预约 # https://wx.scmttec.com/order/subscribe/isCanSubscribe.do?depaCode=4101840002&vaccineCode=8802&id=10162 response = judge_order(departmentCode=departmentCode, departmentVaccineId=departmentVaccineId, vaccineCode=vaccineCode, linkmanId=linkmanId) if response is None: return if not response['ok']: # print(response) print('[error]: 没有可预约的疫苗... , {}'.format( response.get('msg', 'error_info'))) return if response['data'] == 0: print('[error]: 该社区暂时没有可预约信息...') return ##################################################################### ##################################################################### # 第二步,获取疫苗信息 # https://wx.scmttec.com/base/department/vaccine.do?vaccineCode=8802&depaCode=4101840002&departmentVaccineId=10162&isShowDescribtion=false response = get_vaccine_info(depaCode=departmentCode, depaVaccId=departmentVaccineId, vaccineCode=vaccineCode) response = get_server_time() ##################################################################### ##################################################################### # 第三步,判断是否需要注册 # https://wx.scmttec.com/passport/register/isNeedRegister.do?vaccineCode=8802&depaCode=4101840002&linkmanId=8350927&departmentVaccineId=10162 # response = judge_isNeedRegister(departmentCode=departmentCode, departmentVaccineId=departmentVaccineId, # vaccineCode=vaccineCode, linkmanId=linkmanId) # if response is None: # return # if not response['ok'] or response['data'] == 0: # print('[error]: 需要注册...') # print(response) # return ##################################################################### ##################################################################### # 第四步,选择针数 # https://wx.scmttec.com/order/subscribe/workDays.do?depaCode=4101840002&linkmanId=8350927&vaccCode=8802&vaccIndex=1&departmentVaccineId=10162 response = workdays(departmentCode=departmentCode, departmentVaccineId=departmentVaccineId, vaccineCode=vaccineCode, vaccIndex=cfg.vaccIndex, linkmanId=linkmanId) if response is None: return if not response['ok']: print('[error]: 针数 {} 没有可预约日期, {}'.format(cfg.vaccIndex, response['msg'])) return ##################################################################### ##################################################################### # 第五步,同时获取每一天的可预约的人数 dataList = [d.replace('-', '') for d in response['data']['dateList']] days = ','.join(dataList) response = findSubscribeAmountByDays( departmentCode=departmentCode, departmentVaccineId=departmentVaccineId, vaccineCode=vaccineCode, vaccIndex=cfg.vaccIndex, days=days) if response is None: return if not response['ok']: print('[error]: 针数: {}, 日期: {}不可预约, {}'.format(cfg.vaccIndex, days, response['msg'])) return subscribeDates = response['data'] if len(subscribeDates) == 0: print('[error]: 可订阅天数为0...') return # 遍历所有的时间段,直到预约成功 flag, response = loop_order_until_success( departmentCode=departmentCode, departmentVaccineId=departmentVaccineId, vaccineCode=vaccineCode, vaccIndex=cfg.vaccIndex, subscribeDates=response['data'], linkmanId=linkmanId) if response is None: return if flag: subscribeId = response['subscribeId'] response = get_my_order_info_by_subscribeId(subscribeId=subscribeId) save_json( response, osp.join(cfg.save_departments_info_root, cfg.VACCINDE_INFO[cfg.customId], 'order_success.json')) print_my_order_success_info(data=response) else: print('[error]: 所有全部预约失败!') return response
def check_order_number(departmentCode, departmentVaccineId, linkmanId=8350927, username=None): ##################################################################### # 如果用户名不为空,根据传入的用户名来获取 linkmanId if username is not None: linkmanId = get_linkmanId_by_name(username) if linkmanId is None: print('[error]: 输入的用户名 {} 没有在系统中注册'.format(username)) return 0 ##################################################################### ##################################################################### # 根据社区疫苗编号获取该社区的信息,从而获取到该社区是预约哪一价的疫苗,机获取疫苗编号 vaccineCode response = get_department_vaccine_info(depaVaccId=departmentVaccineId) if response is None: return 0 if not response['ok']: print('[error]: 没有找到该社区的信息... , {}'.format(response['msg'])) return 0 departmentName = response['data']['departmentName'] vaccineCode = response['data']['vaccineCode'] ##################################################################### ##################################################################### # 第一步,判断是否可预约 # https://wx.scmttec.com/order/subscribe/isCanSubscribe.do?depaCode=4101840002&vaccineCode=8802&id=10162 response = judge_order(departmentCode=departmentCode, departmentVaccineId=departmentVaccineId, vaccineCode=vaccineCode, linkmanId=linkmanId) if response is None: return 0 if not response['ok']: # print(response) print('[error]: 没有可预约的疫苗... , {}'.format( response.get('msg', 'error_info'))) return 0 if response['data'] == 0: print('[error]: 该社区暂时没有可预约信息...') return 0 ##################################################################### ##################################################################### # 第二步,获取疫苗信息 # https://wx.scmttec.com/base/department/vaccine.do?vaccineCode=8802&depaCode=4101840002&departmentVaccineId=10162&isShowDescribtion=false response = get_vaccine_info(depaCode=departmentCode, depaVaccId=departmentVaccineId, vaccineCode=vaccineCode) response = get_server_time() ##################################################################### ##################################################################### # 第三步,判断是否需要注册 # https://wx.scmttec.com/passport/register/isNeedRegister.do?vaccineCode=8802&depaCode=4101840002&linkmanId=8350927&departmentVaccineId=10162 # response = judge_isNeedRegister(departmentCode=departmentCode, departmentVaccineId=departmentVaccineId, # vaccineCode=vaccineCode, linkmanId=linkmanId) # if response is None: # return 0 # if not response['ok'] or response['data'] == 0: # print('[error]: 需要注册..., response : ', response) # # print(response) # return 0 ##################################################################### ##################################################################### # 第四步,选择针数 # https://wx.scmttec.com/order/subscribe/workDays.do?depaCode=4101840002&linkmanId=8350927&vaccCode=8802&vaccIndex=1&departmentVaccineId=10162 response = workdays(departmentCode=departmentCode, departmentVaccineId=departmentVaccineId, vaccineCode=vaccineCode, vaccIndex=cfg.vaccIndex, linkmanId=linkmanId) if response is None: return 0 if not response['ok']: print('[error]: 针数 {} 没有可预约日期, {}'.format(cfg.vaccIndex, response['msg'])) return 0 ##################################################################### ##################################################################### # 第五步,同时获取每一天的可预约的人数 dataList = [d.replace('-', '') for d in response['data']['dateList']] days = ','.join(dataList) response = findSubscribeAmountByDays( departmentCode=departmentCode, departmentVaccineId=departmentVaccineId, vaccineCode=vaccineCode, vaccIndex=cfg.vaccIndex, days=days) if response is None: return 0 if not response['ok']: print('[error]: 针数: {}, 日期: {}不可预约, {}'.format(cfg.vaccIndex, days, response['msg'])) return 0 subscribeDates = response['data'] if len(subscribeDates) == 0: print('[error]: 可订阅天数为0...') return 0 for sub_data in subscribeDates: # "maxSub":461, "day":"20210114" maxSub = sub_data['maxSub'] date = sub_data['day'] print('日期:{}可预约人数:{}'.format(date, maxSub)) if maxSub != 0: # TODO 发送短信提示,该日期可以预约 print('日期:{}可预约人数:{}'.format(date, maxSub)) if len(departmentName) > 12: departmentName = departmentName[0:12] # print(departmentName) send_text_message([departmentName, str(maxSub)]) return subscribeDates return 0