Advertisement
Guest User

Untitled

a guest
May 4th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.78 KB | None | 0 0
  1. <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  2. <SOAP-ENV:Header/>
  3. <SOAP-ENV:Body>
  4. <ns2:MultiAvailabilityResponse xmlns:ns2="http://www.derbysoft.com/doorway" Status="Successful" Token="187be58c62c2f2515b5d78ee">
  5. <ns2:Availabilities>
  6. <ns2:Availability CurrencyCode="GBP" HotelCode="HY-LONGE">
  7. <ns2:GuestCount AdultCount="1" ChildCount="0"/>
  8. <ns2:RoomTypes>
  9. <ns2:RoomType RoomTypeCode="KING" RoomTypeName="Andaz King">
  10. <ns2:RoomTypeDescription>A 29-square-metre room ,Modern furnishings include oversized work desk, plus bathroom with fast-fill tub and heated towel rail.</ns2:RoomTypeDescription>
  11. </ns2:RoomType>
  12. <ns2:RoomType RoomTypeCode="TWIN" RoomTypeName="Andaz Twin">
  13. <ns2:RoomTypeDescription>A 29-square-metre room ,Modern furnishings include oversized work desk, plus bathroom with fast-fill tub and heated towel rail.</ns2:RoomTypeDescription>
  14. </ns2:RoomType>
  15. <ns2:RoomType RoomTypeCode="QUEN" RoomTypeName="Andaz Queen">
  16. <ns2:RoomTypeDescription>A 26-square-metre room ,Modern furnishings include oversized work desk, plus bathroom with fast-fill tub and heated towel rail.</ns2:RoomTypeDescription>
  17. </ns2:RoomType>
  18. </ns2:RoomTypes>
  19. <ns2:RatePlans>
  20. <ns2:RatePlan RatePlanCode="49584WADPF2" RatePlanName="Advance Purchase">
  21. <ns2:RatePlanDescription>Advance Purchase</ns2:RatePlanDescription>
  22. </ns2:RatePlan>
  23. <ns2:RatePlan RatePlanCode="49584WADPF" RatePlanName="Advance Purchase">
  24. <ns2:RatePlanDescription>Advance Purchase</ns2:RatePlanDescription>
  25. </ns2:RatePlan>
  26. <ns2:RatePlan RatePlanCode="49584IPRTF" RatePlanName="Partner Rate">
  27. <ns2:RatePlanDescription>Partner Rate</ns2:RatePlanDescription>
  28. </ns2:RatePlan>
  29. </ns2:RatePlans>
  30. <ns2:RoomRates>
  31. <ns2:RoomRate RatePlanCode="49584WADPF2" RoomTypeCode="KING">
  32. <ns2:Rates>
  33. <ns2:Rate AmountAfterTax="249.900" AmountBeforeTax="249.900" EffectiveDate="2016-05-05" ExpireDate="2016-05-06"/>
  34. </ns2:Rates>
  35. <ns2:Fees>
  36. <ns2:Fee Amount="0.000" ChargeType="Tax" Type="Exclusive" Unit="PER_ROOM_PER_NIGHT"/>
  37. </ns2:Fees>
  38. </ns2:RoomRate>
  39. <ns2:RoomRate RatePlanCode="49584WADPF2" RoomTypeCode="TWIN">
  40. <ns2:Rates>
  41. <ns2:Rate AmountAfterTax="249.900" AmountBeforeTax="249.900" EffectiveDate="2016-05-05" ExpireDate="2016-05-06"/>
  42. </ns2:Rates>
  43. <ns2:Fees>
  44. <ns2:Fee Amount="0.000" ChargeType="Tax" Type="Exclusive" Unit="PER_ROOM_PER_NIGHT"/>
  45. </ns2:Fees>
  46. </ns2:RoomRate>
  47. <ns2:RoomRate RatePlanCode="49584WADPF" RoomTypeCode="QUEN">
  48. <ns2:Rates>
  49. <ns2:Rate AmountAfterTax="249.900" AmountBeforeTax="249.900" EffectiveDate="2016-05-05" ExpireDate="2016-05-06"/>
  50. </ns2:Rates>
  51. <ns2:Fees>
  52. <ns2:Fee Amount="0.000" ChargeType="Tax" Type="Exclusive" Unit="PER_ROOM_PER_NIGHT"/>
  53. </ns2:Fees>
  54. </ns2:RoomRate>
  55. </ns2:RoomRates>
  56. </ns2:Availability>
  57. <ns2:Availability CurrencyCode="USD" HotelCode="HY-CHIRC">
  58. <ns2:GuestCount AdultCount="1" ChildCount="0"/>
  59. <ns2:RoomTypes>
  60. <ns2:RoomType RoomTypeCode="JRSQ" RoomTypeName="JR SUITE 2 QUEEN BEDS">
  61. <ns2:RoomTypeDescription>Rest in sublime comfort on one of two queen signature Hyatt Grand Beds®, fitted with fine linens, down blanket and plump pillows.</ns2:RoomTypeDescription>
  62. </ns2:RoomType>
  63. <ns2:RoomType RoomTypeCode="CLBD" RoomTypeName="REG CLUB 2 DOUBLE BEDS">
  64. <ns2:RoomTypeDescription>one King or two double-sized Hyatt Grand Beds, fitted with luxurious linens, a down blanket and plush pillows</ns2:RoomTypeDescription>
  65. </ns2:RoomType>
  66. </ns2:RoomTypes>
  67. <ns2:RatePlans>
  68. <ns2:RatePlan RatePlanCode="49584IPRTF" RatePlanName="Partner Rate">
  69. <ns2:RatePlanDescription>Partner Rate</ns2:RatePlanDescription>
  70. <ns2:CancelPolicy NonRefundable="true">
  71. <ns2:CancelPenalties/>
  72. </ns2:CancelPolicy>
  73. </ns2:RatePlan>
  74. <ns2:RatePlan RatePlanCode="49584WPAWAF" RatePlanName="Bed and Breakfast">
  75. <ns2:RatePlanDescription>Bed and Breakfast</ns2:RatePlanDescription>
  76. <ns2:CancelPolicy NonRefundable="true">
  77. <ns2:CancelPenalties/>
  78. </ns2:CancelPolicy>
  79. </ns2:RatePlan>
  80. </ns2:RatePlans>
  81. <ns2:RoomRates>
  82. <ns2:RoomRate RatePlanCode="49584IPRTF" RoomTypeCode="JRSQ">
  83. <ns2:Rates>
  84. <ns2:Rate AmountAfterTax="543.134" AmountBeforeTax="466.650" EffectiveDate="2016-05-05" ExpireDate="2016-05-06"/>
  85. </ns2:Rates>
  86. <ns2:Fees>
  87. <ns2:Fee ChargeType="Tax" Percent="16.390" Type="Exclusive"/>
  88. </ns2:Fees>
  89. </ns2:RoomRate>
  90. <ns2:RoomRate RatePlanCode="49584IPRTF" RoomTypeCode="CLBD">
  91. <ns2:Rates>
  92. <ns2:Rate AmountAfterTax="370.004" AmountBeforeTax="317.900" EffectiveDate="2016-05-05" ExpireDate="2016-05-06"/>
  93. </ns2:Rates>
  94. <ns2:Fees>
  95. <ns2:Fee ChargeType="Tax" Percent="16.390" Type="Exclusive"/>
  96. </ns2:Fees>
  97. </ns2:RoomRate>
  98. <ns2:RoomRate RatePlanCode="49584IPRTF" RoomTypeCode="VW2Q">
  99. <ns2:Rates>
  100. <ns2:Rate AmountAfterTax="325.485" AmountBeforeTax="279.650" EffectiveDate="2016-05-05" ExpireDate="2016-05-06"/>
  101. </ns2:Rates>
  102. <ns2:Fees>
  103. <ns2:Fee ChargeType="Tax" Percent="16.390" Type="Exclusive"/>
  104. </ns2:Fees>
  105. </ns2:RoomRate>
  106. </ns2:RoomRates>
  107. </ns2:Availability>
  108. </ns2:Availabilities>
  109. </ns2:MultiAvailabilityResponse>
  110. </SOAP-ENV:Body>
  111.  
  112. def listify(obj):
  113. """To convert each element of SOAP into a list, so processing of response would be easy."""
  114. if isinstance(obj, list):
  115. return obj
  116. return [obj]
  117.  
  118.  
  119. def search_hotels_formatted_response(soap):
  120. """Parse the response."""
  121. soap = xmltodict.parse(soap, process_namespaces=True)
  122.  
  123. # Deal with namespaces
  124. env = 'http://schemas.xmlsoap.org/soap/envelope/:'
  125. doorway = 'http://www.derbysoft.com/doorway:'
  126.  
  127. availability = listify(
  128. soap[env + 'Envelope']
  129. [env + 'Body']
  130. [doorway + 'MultiAvailabilityResponse']
  131. [doorway + 'Availabilities']
  132. [doorway + 'Availability'])
  133.  
  134. # Intermediate data structure to hold room names
  135. names = {
  136. roomtype['@RoomTypeCode']: roomtype['@RoomTypeName']
  137. for _availability in availability
  138. for roomtype in listify(_availability
  139. [doorway + 'RoomTypes']
  140. [doorway + 'RoomType'])
  141. }
  142.  
  143. return_dict = {
  144. 'ibp': 'dbs',
  145. 'rL': sorted([
  146. {
  147. 'rtc': roomrate['@RoomTypeCode'],
  148. 'rpc': roomrate['@RatePlanCode'],
  149. 'rtn': names[roomrate['@RoomTypeCode']],
  150. 'rmt': rate['@AmountBeforeTax'],
  151. 'cur': _availability['@CurrencyCode'],
  152. 'ttc': float(rate['@AmountAfterTax']) - float(rate['@AmountBeforeTax']),
  153. 'egc': 0,
  154. 'long': ''
  155.  
  156. }
  157. for _availability in availability
  158. for roomrate in listify(_availability
  159. [doorway + 'RoomRates']
  160. [doorway + 'RoomRate'])
  161. for rate in listify(roomrate
  162. [doorway + 'Rates']
  163. [doorway + 'Rate'])],
  164. key=lambda x: float(x['rmt'])),
  165. 'hc': _availability['@HotelCode'],
  166. 'hn': ''
  167. }
  168.  
  169. return return_dict
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement