def getSoapClient(url): _INFO('', ['trying get soap client, url = ' + url]) try: client = Client(url) _INFO('', ['Getting Soap Clent, Success']) #print client except Exception, e: _ERROR('', ['Getting Soap Clent, Failed']) sys.exit(-1)
def ctrip_room_parser(taskcontent): result = {} result['para'] = None result['error'] = 0 try: check_in_temp,days_temp,hotel_id_content,city = taskcontent.split('&')[3],taskcontent.split('&')[0], \ taskcontent.split('&')[1],taskcontent.split('&')[2] except Exception, e: _ERROR('ctrip_room_parser', ['Parse taskcontent failed', str(e)]) result['error'] = TASK_ERROR return result
def parsePrice(content_temp, city): all_price = [] content = xmlescape(content_temp).replace('\n', '') #print content_temp try: each_hotel_content_list = rateplans_pat.findall(content) if len(each_hotel_content_list) == 0: return all_price _INFO('ctripHotel::parseRoom', ['Parse price failed because of no hotel found']) except Exception, e: _ERROR('ctripHotel::parseRoom', ['Parse price failed because of no hotel found', str(e)])
def data_writer(room_list, taskcontent): if room_list == []: _ERROR('', ['room_list.size == 0']) return try: InsertHotel_room(room_list) _INFO('', [taskcontent + ' [success]']) _INFO('', ['with ' + str(len(room_list)) + ' values!']) except Exception, e: _ERROR('', [taskcontent + '[failed]']) _ERROR('', [str(e)])
info['rid'] = data[4].encode('utf-8').strip() #source_roomid if (real_source not in opened_source_set): print 'filter\tnot_in_openedSourc_' + source + '\treal_source=' + real_source continue info['rs'] = real_source ori_rt = data[6].encode('utf-8').strip() info['ori_rt'] = ori_rt try: normalized_rt = normalizeRoomType(ori_rt) except Exception ,e: _ERROR('normalize room type',['Error normalize roomType=' + ori_rt]) normalized_rt = ori_rt pass info['rt'] = normalized_rt #room_type info['occu'] = data[7] #occupancy info['bt'] = data[8].encode('utf-8').strip() #bed_type info['size'] = data[9] #size info['floor'] = data[10] #floor # check_in check_in = data[11].encode('utf-8').strip() check_in_vec = check_in.split('-') if len(check_in_vec) != 3: print "filter\tcheck_in_not_format_" + source + "\tcheck_in="+check_in
#flight_ticket info for latest one day flight_ticket_info_value = seat_type + '\t' + real_class + '\t' + ticket_no + '\t' + ticket_stop_id + '\t' + dept_id + '\t' + dest_id + '\t' + update_time + '\t' + str(stop) + '\t' + return_rule + '\t' + str(rest) flight_ticket_sql = "replace into " + flight_ticket_info_sql_table + " (flight_ticket_md5, seat_type,real_class,ticket_no,stop_id,dept_id,dest_id,update_time,stop,return_rule,rest) values ('" + flight_ticket_md5 + "','" + seat_type + "','" + real_class + "','" + ticket_no + "','" + ticket_stop_id + "','" + dept_id + "','" + dest_id + "','" + update_time + "','" + str(stop) + "','" + return_rule + "','" + str(rest) + "');" try: #print 'flight_ticket_sql: ' + flight_ticket_sql cursor.execute(flight_ticket_sql) #print 'flight_ticket_key: ' + flight_ticket_md5 #print 'flight_ticket_value: ' + flight_ticket_info_value flight_ticket_redis[flight_ticket_md5] = flight_ticket_info_value except Exception,e: _ERROR('excute sql fail',['Error','sql_len='+str(len(flight_ticket_sql)),'sql='+flight_ticket_sql]) _ERROR('excute sql fail!',['error code: ' + str(e)]) continue #update update_time else: try: upsql = "update " + flight_ticket_info_sql_table + " set update_time='" + update_time + "' where flight_ticket_md5 ='" + flight_ticket_md5 + "';" cursor.execute(upsql) _INFO('update flight ticket update time',['flight_ticket_md5=' + flight_ticket_md5]) except Exception, e: _ERROR('update update_time error',['error code=' + str(e)]) continue except Exception ,e: _INFO('push flight data',['Error',['execute sql error! sql = ' + selectsql]])
def getRatePlanByHotelCode(client, hotelcode_set, from_date, to_date, city): AllianceID = '15951' SID = '439022' SecretKey = '4F3E7530-391A-45A3-829B-880FFBBC4264' TimeStamp = str(int(time.time())) RequestType = 'OTA_HotelSearch' Signature = Signate(AllianceID, SID, SecretKey, TimeStamp, RequestType) #print Signature req_xml = minidom.getDOMImplementation() dom = req_xml.createDocument(None, 'Request', None) root = dom.documentElement header = dom.createElement('Header') header.setAttribute('AllianceID', AllianceID) header.setAttribute('SID', SID) header.setAttribute('TimeStamp', TimeStamp) header.setAttribute('RequestType', RequestType) header.setAttribute('Signature', Signature) hotel_request = dom.createElement('HotelRequest') request_body = dom.createElement('RequestBody') request_body.setAttribute('xmlns:ns', 'http://www.opentravel.org/OTA/2003/05') request_body.setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance') request_body.setAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema') ns_ota_hsr = dom.createElement('ns:OTA_HotelRatePlanRQ') ns_ota_hsr.setAttribute('Version', '1.0') ns_ota_hsr.setAttribute('TimeStamp', '2012-05-01T00:00:00.000+08:00') ns_rate_plans = dom.createElement('ns:RatePlans') ns_rate_plan = dom.createElement('ns:RatePlan') ns_date_range = dom.createElement('ns:DateRange') ns_date_range.setAttribute('Start', from_date) ns_date_range.setAttribute('End', to_date) ns_rate_plan_candidates = dom.createElement('ns:RatePlanCandidates') for hotelcode in hotelcode_set: ns_rate_plan_candidate = dom.createElement('ns:RatePlanCandidate') ns_rate_plan_candidate.setAttribute('AvailRatesOnlyInd', 'false') ns_hotel_refs = dom.createElement('ns:HotelRefs') ns_hotel_ref = dom.createElement('ns:HotelRef') ns_hotel_ref.setAttribute('HotelCode', hotelcode) ns_hotel_refs.appendChild(ns_hotel_ref) ns_rate_plan_candidate.appendChild(ns_hotel_refs) ns_rate_plan_candidates.appendChild(ns_rate_plan_candidate) ns_rate_plan.appendChild(ns_date_range) ns_rate_plan.appendChild(ns_rate_plan_candidates) ns_rate_plans.appendChild(ns_rate_plan) ns_ota_hsr.appendChild(ns_rate_plans) request_body.appendChild(ns_ota_hsr) hotel_request.appendChild(request_body) root.appendChild(header) root.appendChild(hotel_request) xml_str = dom.toxml().decode('utf-8') room_list = [] try: resp = client.service.Request(xml_str) resp = resp.__str__() _INFO('client.service.Request', ['hotelcode = ' + hotelcode + ', len = ' + str(len(resp))]) room_list = parsePrice(resp, city) #print 'ok2' _INFO('ctripHotel::parsePrice', ['Parsed ' + str(len(room_list)) + ' values']) except Exception, e: _ERROR('ctripHotel::getRatePlanByHotelCode', ['hotelcode = ' + str(hotelcode), str(e)]) return room_list
except Exception, e: _ERROR('ctripHotel::parseRoom', ['Parse price failed because of no hotel found', str(e)]) for each_hotel_content in each_hotel_content_list: room = Room() try: room.source_hotelid = pattern_search(hotelcode_pat, each_hotel_content) if room.source_hotelid == 'NULL': _INFO('ctripHotel::parseRoom', ['Cannot parse this hotel id']) except Exception, e: _ERROR( 'ctripHotel::parseRoom', ['Cannot parse this hotel', str(e)]) #print room.source_hotelid try: each_room_content_list = rateplan_pat.findall(each_hotel_content) if len(each_room_content_list) == 0: _ERROR('ctripHotel::parseRoom', ['Parse this room failed']) return room_list except Exception, e: _ERROR('ctripHotel::parseRoom', ['Parse this room failed', e]) return room_list for each_room_content in each_room_content_list: #print each_room_content try: room.source_roomid = pattern_search(roomcode_pat,
flight_ticket_sql = "replace into " + flight_ticket_info_sql_table + " (flight_ticket_md5, seat_type,real_class,ticket_no,stop_id,dept_id,dest_id,update_time,stop,return_rule,rest) values ('" + flight_ticket_md5 + "','" + seat_type + "','" + real_class + "','" + ticket_no + "','" + ticket_stop_id + "','" + dept_id + "','" + dest_id + "','" + update_time + "','" + str( stop) + "','" + return_rule + "','" + str(rest) + "');" try: #print 'flight_ticket_sql: ' + flight_ticket_sql cursor.execute(flight_ticket_sql) #print 'flight_ticket_key: ' + flight_ticket_md5 #print 'flight_ticket_value: ' + flight_ticket_info_value flight_ticket_redis[ flight_ticket_md5] = flight_ticket_info_value except Exception, e: _ERROR('excute sql fail', [ 'Error', 'sql_len=' + str(len(flight_ticket_sql)), 'sql=' + flight_ticket_sql ]) _ERROR('excute sql fail!', ['error code: ' + str(e)]) continue #update update_time else: try: upsql = "update " + flight_ticket_info_sql_table + " set update_time='" + update_time + "' where flight_ticket_md5 ='" + flight_ticket_md5 + "';" cursor.execute(upsql) _INFO('update flight ticket update time', ['flight_ticket_md5=' + flight_ticket_md5]) except Exception, e: _ERROR('update update_time error', ['error code=' + str(e)]) continue
info['rid'] = data[4].encode('utf-8').strip() #source_roomid if (real_source not in opened_source_set): print 'filter\tnot_in_openedSourc_' + source + '\treal_source=' + real_source continue info['rs'] = real_source ori_rt = data[6].encode('utf-8').strip() info['ori_rt'] = ori_rt try: normalized_rt = normalizeRoomType(ori_rt) except Exception, e: _ERROR('normalize room type', ['Error normalize roomType=' + ori_rt]) normalized_rt = ori_rt pass info['rt'] = normalized_rt #room_type info['occu'] = data[7] #occupancy info['bt'] = data[8].encode('utf-8').strip() #bed_type info['size'] = data[9] #size info['floor'] = data[10] #floor # check_in check_in = data[11].encode('utf-8').strip() check_in_vec = check_in.split('-') if len(check_in_vec) != 3: print "filter\tcheck_in_not_format_" + source + "\tcheck_in=" + check_in