def get_house_info(ch, method, properties, body): username = method.consumer_tag global headers headers = get_headers(username) body_json = json.loads(body.decode()) ConstructionName = body_json['ConstructionName'] BuildName = body_json['BuildName'] Id = body_json['Id'] detail_url = 'http://www.xiaozijia.cn/HouseInfo/' + str(Id) try: response = requests.get(detail_url, headers=headers, timeout=20) html_json = response.json() if not html_json.get('State'): log.error( '请求错误,url="{}",BuildName="{}",ConstructionName="{}",Id="{}"'. format(detail_url, BuildName, ConstructionName, Id)) channel.basic_publish(exchange='', routing_key=detail_queue, body=body) ch.basic_ack(delivery_tag=method.delivery_tag) return html_json['ConstructionName'] = ConstructionName html_json['BuildName'] = BuildName coll_detail.insert_one(html_json) log.info('插入一个数据,data="{}"'.format(html_json)) except Exception as e: headers = get_headers(username) log.error( '请求错误,url="{}",BuildName="{}",ConstructionName="{}",Id="{}",e="{}"' .format(detail_url, BuildName, ConstructionName, Id, e)) channel.basic_publish(exchange='', routing_key=detail_queue, body=body) ch.basic_ack(delivery_tag=method.delivery_tag)
def get_house_info(self, ch, method, properties, body): """ 消费xiaozijia_build队列,请求,入小区库,并放入房号页 :param ch: :param method: :param properties: :param body: :return: """ body_json = json.loads(body.decode()) IdSub = body_json['IdSub'] ConstructionName = body_json['ConstructionName'] BuildName = body_json['Name'] ConstructionId = body_json['ConstructionId'] house_url = 'http://www.xiaozijia.cn/HousesForJson/' + IdSub + '/1' try: response = requests.get(house_url, headers=self.headers, timeout=20) html_json = response.json() for i in html_json: i['ConstructionName'] = ConstructionName i['ConstructionId'] = ConstructionId i['BuildName'] = BuildName i['IdSub'] = IdSub channel.basic_publish(exchange='', routing_key=detail_queue, body=json.dumps(i)) coll_house.insert_one(i) log.info(i) ch.basic_ack(delivery_tag=method.delivery_tag) except Exception as e: self.headers = get_headers(self.user_name) log.error( '请求错误,url="{}",BuildName="{}",ConstructionName="{}",ConstructionId="{}",IdSub="{}",e="{}"' .format(house_url, BuildName, ConstructionName, ConstructionId, IdSub, e)) channel.basic_publish(exchange='', routing_key=house_queue, body=body) ch.basic_ack(delivery_tag=method.delivery_tag)
def get_build_info(self, ch, method, properties, body): """ 消费xiaozijia_build队列,请求,入小区库,并放入房号页 :param ch: :param method: :param properties: :param body: :return: """ body_json = json.loads(body.decode()) ConstructionPhaseId = body_json['ConstructionPhaseId'] ConstructionName = body_json['ConstructionName'] ConstructionId = body_json['ConstructionId'] build_url = 'http://www.xiaozijia.cn/HousesForJson/' + ConstructionPhaseId + '/2' try: response = requests.get(build_url, headers=self.headers, timeout=20) html_json = response.json() if not html_json: log.info('小区没有楼栋,url={}'.format(build_url)) for i in html_json: i['ConstructionName'] = ConstructionName i['ConstructionId'] = ConstructionId channel.basic_publish(exchange='', routing_key=house_queue, body=json.dumps(i)) coll_build.insert_one(i) log.info(i) except Exception as e: self.headers = get_headers(self.user_name) log.error( '请求错误,url="{}",ConstructionPhaseId="{}",ConstructionName="{}",ConstructionId="{}",e="{}"' .format(build_url, ConstructionPhaseId, ConstructionName, ConstructionId, e)) channel.basic_publish(exchange='', routing_key=build_queue, body=body) ch.basic_ack(delivery_tag=method.delivery_tag)
setting['xiaozijia']['mongo']['port'], user_name=setting['xiaozijia']['mongo']['user_name'], password=setting['xiaozijia']['mongo']['password']) coll_build = m.connect[setting['xiaozijia']['mongo']['db']][ setting['xiaozijia']['mongo']['build_coll']] # rabbit r = Rabbit(setting['xiaozijia']['rabbit']['host'], setting['xiaozijia']['rabbit']['port']) channel = r.get_channel() build_queue = setting['xiaozijia']['rabbit']['queue']['xiaozijia_build'] house_queue = setting['xiaozijia']['rabbit']['queue']['xiaozijia_house'] channel.queue_declare(queue=build_queue) channel.queue_declare(queue=house_queue) headers = get_headers() def get_build_info(ch, method, properties, body): """ 消费xiaozijia_build队列,请求,入小区库,并放入房号页 :param ch: :param method: :param properties: :param body: :return: """ global headers body_json = json.loads(body.decode()) ConstructionPhaseId = body_json['ConstructionPhaseId'] ConstructionName = body_json['ConstructionName']
def __init__(self, username): self.headers = get_headers(username) self.user_name = username