Esempio n. 1
0
def getServiceDetails(objectDataXMLPath):
	"""
	Purpose: Utility method to extract the URL and containery from objectdata.xml which was exported from CM / PM. This method relies on the fact that objectdata.xml has a standardized structure
	Input: Path to objedata.xml
	Returns: Dictionary object comprising of URL and Container Key
	"""
	try:
		mylogger.info("BEGIN -- getServiceDetails")
		objectdatatree = utils.parseXML (objectDataXMLPath)
		serviceDict = {"apiURL" : "" , "apiContainerKey" : ""}
		for exportConfig in objectdatatree:
			if (exportConfig.tag.find("ExportObjectConfiguration") > 0):
				for exportServiceEP in exportConfig:
					if (exportServiceEP.tag.find("ExportService") > 0):
						for serviceEP in exportServiceEP:
							if (serviceEP.tag.find("ExportServiceEndpoint") > 0):
								for entries in serviceEP:
									if (entries.tag.find("ServiceEndpoint") > 0):
										for child in entries:
											if (child.tag.find("Url") > 0):
												serviceDict ["apiURL"] = child.text
											if (child.tag.find("ContainerKey") > 0) :
												serviceDict ["apiContainerKey"] = child.text
											
							
		return serviceDict
		mylogger.info("END -- getServiceDetails")		
	except:
		mylogger.error(traceback.format_exc())
Esempio n. 2
0
def handle_result_ajax_v3(rpc, destination, price, startDate, endDate, response):
	starthandle_result_ajax_v3 = quota.get_request_cpu_usage()
	try:
		result = rpc.get_result()
		if result.status_code == 200:
			logging.info("handle_result_ajax_v3() : RPC response SUCCESS code: 200")
			f = utils.parseXML(result.content.replace('|', ''))
			
			
			counter = 1
			hotelList = list()
			for hotel in f:
				if hotel['address'] is not None:
					hotelDict = dict()
					hotelPrice = hotel['price'].replace('£','')
					hotelPrice = hotelPrice.replace(',','')
					hotelPrice = float(hotelPrice)
					
					hotelDict['name'] = hotel['name']
					# [ST]TODO: Move price, startdate and enddate to LMHotelPriceAndDate db.Model
					hotelDict['startdate'] = startDate.date().isoformat()
					hotelDict['enddate'] = endDate.date().isoformat()
					hotelDict['price'] = hotelPrice
					hotelDict['address'] = hotel['address']
					hotelDict['destination'] = destination
					hotelDict['index'] = counter
					
					if hotel['rating'] is not None:
						rating = hotel['rating']
						rating = rating.split("/").pop()
						rating = rating.split('-')[1]
						hotelDict['rating'] = rating
					
					if hotel['url'] is not None:
						hotelLink = hotel['url']
						hotelLinkArray = hotelLink.split("&")
						for param in hotelLinkArray:
							if param.startswith("propertyIds"):
								propertyIdValue = param.split("=")[1]
								hotelDict['locationid'] = propertyIdValue.split('-',1)[0]
								if len(hotelDict['locationid']) == 1:
									hotelDict['locationid'] = "00000"+hotelDict['locationid']
								if len(hotelDict['locationid']) == 2:
									hotelDict['locationid'] = "0000"+hotelDict['locationid']
								if len(hotelDict['locationid']) == 3:
									hotelDict['locationid'] = "000"+hotelDict['locationid']
								if len(hotelDict['locationid']) == 4:
									hotelDict['locationid'] = "00"+hotelDict['locationid']
								if len(hotelDict['locationid']) == 5:
									hotelDict['locationid'] = "0"+hotelDict['locationid']
								
								hotelDict['propertyids'] = propertyIdValue
							
							if param.startswith("hotelRequestId"):
								hotelDict['hotelrequestid'] = param.split("=")[1]
						
						hotelDict['productdetailsurl'] = str(hotelLink).replace('tabId=information','tabId=rooms')
					else:
						hotelDict['locationid'] = destination+str(counter)
					counter += 1
					hotelList.append(hotelDict)
			
			# [ST] WARNING: With this execution we cannot filter by price on the first search of a destination, startdate and enddate
			
			global_mashup['hotels'] = hotelList
			path = os.path.join(os.path.dirname(__file__),'templates/version3/includes/hotels.html')
			response.out.write(template.render(path, global_mashup))
			
			# After sending the response, add the datastore write to the taskqueue
			for hotel in hotelList:
				# [ST]TODO: Lookup the Hotel by key_name (locationid) before adding a taskqueue instance for it
				existingHotel = datamodel.LMHotel.get_by_key_name(hotel['locationid'])
				logging.info(existingHotel)
				if existingHotel is None:
					logging.info("handle_result_ajax_v3() : Hotel with location id "+str(hotel['locationid'])+" DOES NOT exist. Assigning task to queue")
					taskqueue.add(queue_name='hotelsqueue', url='/hotelsworker', params={'destination':destination, 'data':json.dumps(hotel)})
				else: 
					logging.info("handle_result_ajax_v3() : Hotel with location id "+str(hotel['locationid'])+" DOES exist. No task queue necessary")
				# Add the new price data for this hotel
				taskqueue.add(queue_name='hotelspricequeue', url='/hotelspriceworker', params={'destination':destination, 'locationid':hotel['locationid'], 'price':hotel['price'], 'startDate':hotel['startdate'], 'endDate':hotel['enddate']})
			
		
		elif result.status_code == 400:
			logging.info("RPC response ERROR code: 400")
			path = os.path.join(os.path.dirname(__file__),'templates/version3/includes/no-results.html')
			response.out.write(template.render(path, global_mashup))
	except urlfetch.DownloadError:
		logging.info("RPC response DEADLINE OR DOWNLOAD ERROR")
		path = os.path.join(os.path.dirname(__file__),'templates/version3/includes/service-error.html')
		response.out.write(template.render(path, global_mashup))