-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsp.py
66 lines (50 loc) · 2.34 KB
/
sp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
import pprint
import os
import uuid
from xml.etree import ElementTree as ET
import requests
import datetime as datetime
# url of rbs API
url = 'https://rbs.gta-travel.com/rbscnapi/RequestListenerServlet'
from_date = datetime.date(2017, 4, 5)
to_date = datetime.date(2017, 4, 6)
counter = (to_date - from_date).days
pp = pprint.PrettyPrinter(indent=4)
def daterange(start_date, end_date):
for n in range(int ((end_date - start_date).days)):
yield start_date + datetime.timedelta(n)
pp.pprint(str('/// /// /// Get Daily Price of Searching_Hotel_Price_Pax /// /// ///'))
pp.pprint('how many days: ' + str(counter))
hotel_codes = []
with open('hotel_codes', 'r') as file:
for line in file:
# pp.pprint(line)
city_code, item_code = line.rstrip().split('_')
hotel_codes.append(dict([('city_code', city_code), ('item_code', item_code), ('missing_price', [])]))
pp.pprint(hotel_codes)
search_tree = ET.parse(os.path.join(os.getcwd(), 'SearchHotelPricePaxRequest.xml'))
for hotel_code in hotel_codes:
pp.pprint('Searching Price for ' + hotel_code['city_code'] + ' ' + hotel_code['item_code'])
for single_date in daterange(from_date, to_date):
pp.pprint('Searching date: ' + single_date.strftime("%Y-%m-%d"))
search_tree.find('.//ItemDestination').set('DestinationCode', hotel_code['city_code'])
search_tree.find('.//ItemCode').text = hotel_code['item_code']
for i in range(3):
pp.pprint('Pax #: ' + str(i + 1))
search_tree.find('.//PaxRoom').set('Adults', str(i + 1))
r = requests.post(url, data=ET.tostring(search_tree.getroot(), encoding='UTF-8', method='xml'))
pp.pprint('Search price status code: ' + str(r.status_code))
# pp.pprint(r.headers)
pp.pprint('Search price Response body: ' + r.text)
r_tree = ET.fromstring(r.text)
if (r_tree.find('.//RoomPrice') == None):
hotel_code['missing_price'].append('Pax ' + str(i + 1) + ': ' + single_date.strftime("%Y-%m-%d"))
pp.pprint('Alert: Price not returned... ')
else:
# pp.pprint('Gross: ' + str(r_tree.find('.//RoomPrice').get('Gross')))
for room_cat in r_tree.find('.//RoomCategories'):
pp.pprint('Id: ' + str(room_cat.get('Id')))
pp.pprint('Id: ' + str(room_cat.find('.//Description').text))
pp.pprint('/// /// /// Test Result /// /// ///')
pp.pprint(hotel_codes)