def post_inventory(self, inventories, is_online=1): if not inventories: raise gen.Return(False) inventory_data = self.generate_inventory_data(inventories, is_online) track_id = self.generate_track_id(inventories[0].roomtype_id) params = { 'track_id': track_id, 'data': json_encode({'list': [inventory_data]}) } Log.info("push inventory roomtype {}: {}".format( inventories[0].roomtype_id, params)) if not IS_PUSH_TO_STOCK: raise gen.Return(True) url = API['STOCK'] + '/stock/update_inventory?is_async=false' r = yield AsyncHTTPClient().fetch(url, method='POST', body=urllib.urlencode(params)) Log.info("push inventory roomtype {} response {}".format( inventories[0].roomtype_id, r.body)) resp = json.loads(r.body) raise gen.Return(resp and resp['errcode'] == 0)
def finish_json(self, errcode=0, errmsg=None, result=None): self.set_header("Content-Type", "application/json; charset=UTF-8") #self.set_header("Access-Control-Allow-Origin", "*") resp_json = json_encode({'errcode': errcode, 'errmsg': errmsg, 'result': result}) if self.is_jsonp: resp_json = "{}({})".format(self.callback_fun_name, resp_json) self.finish(resp_json)
def post_cancel_rules(self, cancel_rule_data): if not IS_PUSH_TO_STOCK: return track_id = self.generate_track_id(1) data = {'track_id': track_id, 'data': json_encode({'list': cancel_rule_data})} self.log.info("<<push cancel rules>> request: {}".format(data)) url = API['STOCK'] + '/stock/update_cancel_rule?is_async=false' r = req.post(url, data) self.log.info("<<push cancel rules>> response: {}".format(r.text))
def post_roomrates(self, roomrate_data): if not IS_PUSH_TO_STOCK: return track_id = self.generate_track_id(2) data = {'track_id': track_id, 'data': json_encode({'list': roomrate_data})} self.log.info("push roomrates {}".format(data)) url = API['STOCK'] + '/stock/update_room_rate?is_async=false' r = req.post(url, data) self.log.info("push roomrates resp {}".format(r.text))
def post_cancel_rule(self, rateplan): if not IS_PUSH_TO_STOCK: return rateplan_data = self.generate_cancel_rule_data(rateplan) track_id = self.generate_track_id(rateplan.id) data = {'track_id': track_id, 'data': json_encode({'list': [rateplan_data]})} self.log.info("<<push rateplan {}>> data:{}".format(rateplan.id, data)) url = API['STOCK'] + '/stock/update_cancel_rule?is_async=false' r = req.post(url, data) self.log.info("<<push rateplan {}>> response:{}".format(rateplan.id, r.text))
def post_roomrate(self, merchant_id, roomrate): if not IS_PUSH_TO_STOCK: return roomrate_datas = self.generate_roomrate_datas(merchant_id, roomrate) track_id = self.generate_track_id(roomrate.id) data = {'track_id': track_id, 'data': json_encode({'list': roomrate_datas})} self.log.info(data) url = API['STOCK'] + '/stock/update_room_rate?is_async=false' r = req.post(url, data) self.log.info(r.text)
def post_rateplans(self, rateplan_data): if not IS_PUSH_TO_STOCK: return track_id = self.generate_track_id(0) data = {'list': rateplan_data} params = {'track_id': track_id, 'data': json_encode(data)} self.log.info(params) url = API['STOCK'] + '/stock/update_rate_plan?is_async=false' r = req.post(url, data=params) self.log.info(r.text)
def finish_json(self, errcode=0, errmsg=None, result=None): self.set_header("Content-Type", "application/json; charset=UTF-8") #self.set_header("Access-Control-Allow-Origin", "*") resp_json = json_encode({ 'errcode': errcode, 'errmsg': errmsg, 'result': result }) if self.is_jsonp: resp_json = "{}({})".format(self.callback_fun_name, resp_json) self.finish(resp_json)
def post_roomrates(self, roomrate_data): if not IS_PUSH_TO_STOCK: return track_id = self.generate_track_id(2) data = { 'track_id': track_id, 'data': json_encode({'list': roomrate_data}) } self.log.info("push roomrates {}".format(data)) url = API['STOCK'] + '/stock/update_room_rate?is_async=false' r = req.post(url, data) self.log.info("push roomrates resp {}".format(r.text))
def post_cancel_rules(self, cancel_rule_data): if not IS_PUSH_TO_STOCK: return track_id = self.generate_track_id(1) data = { 'track_id': track_id, 'data': json_encode({'list': cancel_rule_data}) } self.log.info("<<push cancel rules>> request: {}".format(data)) url = API['STOCK'] + '/stock/update_cancel_rule?is_async=false' r = req.post(url, data) self.log.info("<<push cancel rules>> response: {}".format(r.text))
def post_rateplans(self, rateplan_data): if not IS_PUSH_TO_STOCK: return track_id = self.generate_track_id(0) data = {'list': rateplan_data} params = {'track_id': track_id, 'data': json_encode(data) } self.log.info(params) url = API['STOCK'] + '/stock/update_rate_plan?is_async=false' r = req.post(url, data=params) self.log.info(r.text)
def post_roomrate(self, merchant_id, roomrate): if not IS_PUSH_TO_STOCK: return roomrate_datas = self.generate_roomrate_datas(merchant_id, roomrate) track_id = self.generate_track_id(roomrate.id) data = { 'track_id': track_id, 'data': json_encode({'list': roomrate_datas}) } self.log.info(data) url = API['STOCK'] + '/stock/update_room_rate?is_async=false' r = req.post(url, data) self.log.info(r.text)
def post_cancel_rule(self, rateplan): if not IS_PUSH_TO_STOCK: return rateplan_data = self.generate_cancel_rule_data(rateplan) track_id = self.generate_track_id(rateplan.id) data = { 'track_id': track_id, 'data': json_encode({'list': [rateplan_data]}) } self.log.info("<<push rateplan {}>> data:{}".format(rateplan.id, data)) url = API['STOCK'] + '/stock/update_cancel_rule?is_async=false' r = req.post(url, data) self.log.info("<<push rateplan {}>> response:{}".format( rateplan.id, r.text))
def post_inventory(self, inventories, is_online=1): if not inventories: self.log.info('no inventoris') return inventory_data = self.generate_inventory_data(inventories, is_online) track_id = generate_track_id(inventories[0].roomtype_id) params = {'track_id': track_id, 'data': json_encode({'list': [inventory_data]})} self.log.info(params) url = API['STOCK'] + '/stock/update_inventory?is_async=false' if not IS_PUSH_TO_STOCK: return r = req.post(url, data=params) self.log.info(r.text)
def post_roomrate(self, merchant_id, roomrate): roomrate_datas = self.generate_roomrate_datas(merchant_id, roomrate) track_id = self.generate_track_id(roomrate.id) data = {'track_id': track_id, 'data': json_encode({'list': roomrate_datas})} Log.info("<<push roomrate {}>>: {}".format(roomrate.id, data)) if not IS_PUSH_TO_STOCK: raise gen.Return(True) url = API['STOCK'] + '/stock/update_room_rate?is_async=false' body = urllib.urlencode(data) r = yield AsyncHTTPClient().fetch(url, method="POST", body=body) resp = json.loads(r.body) Log.info("<<push roomrate {}>> response:{}".format(roomrate.id, r.body)) if resp and resp['errcode'] == 0: raise gen.Return(True) else: raise gen.Return(False)
def post_cancel_rule(self, rateplan): rateplan_data = self.generate_cancel_rule_data(rateplan) track_id = self.generate_track_id(rateplan.id) data = {'track_id': track_id, 'data': json_encode({'list': [rateplan_data]})} Log.info("<<push cancel rule rateplan {}>> data:{}".format(rateplan.id, data)) if not IS_PUSH_TO_STOCK: raise gen.Return(True) url = API['STOCK'] + '/stock/update_cancel_rule?is_async=false' body = urllib.urlencode(data) r = yield AsyncHTTPClient().fetch(url, method="POST", body=body) resp = json.loads(r.body) Log.info("<<push cancel rateplan {}>> response:{}".format(rateplan.id, resp)) if resp and resp['errcode'] == 0: raise gen.Return(True) else: raise gen.Return(False)
def post_inventory(self, inventories, is_online=1): if not inventories: return True inventory_data = self.generate_inventory_data(inventories, is_online) track_id = self.generate_track_id(inventories[0].roomtype_id) params = {'track_id': track_id, 'data': json_encode({'list': [inventory_data]})} Log.info("push inventory roomtype {}: {}".format(inventories[0].roomtype_id, params)) if not IS_PUSH_TO_STOCK: return True url = API['STOCK'] + '/stock/update_inventory?is_async=false' r = requests.post(url, data=params) Log.info("push inventory roomtype {} response {}".format(inventories[0].roomtype_id, r.text)) return r.status_code == 200 and r.json()['errcode'] == 0
def post_inventory(self, inventories, is_online=1): if not inventories: self.log.info('no inventoris') return inventory_data = self.generate_inventory_data(inventories, is_online) track_id = generate_track_id(inventories[0].roomtype_id) params = { 'track_id': track_id, 'data': json_encode({'list': [inventory_data]}) } self.log.info(params) url = API['STOCK'] + '/stock/update_inventory?is_async=false' if not IS_PUSH_TO_STOCK: return r = req.post(url, data=params) self.log.info(r.text)
def post_rateplan(self, rateplan): rateplan_data = self.generate_rateplan_data(rateplan) track_id = self.generate_track_id(rateplan_data['rate_plan_id']) data = {'list': [rateplan_data]} params = {'track_id': track_id, 'data': json_encode(data)} Log.info('push rateplan {} : {}'.format(rateplan.id, params)) if not IS_PUSH_TO_STOCK: raise gen.Return(True) url = API['STOCK'] + '/stock/update_rate_plan?is_async=false' body = urllib.urlencode(params) r = yield AsyncHTTPClient().fetch(url, method="POST", body=body) resp = json.loads(r.body) Log.info("<<push rateplan {}>> response:{}".format(rateplan.id, resp)) if resp and resp['errcode'] == 0: raise gen.Return(True) else: raise gen.Return(False)
def post_inventory(self, inventories, is_online=1): if not inventories: raise gen.Return(False) inventory_data = self.generate_inventory_data(inventories, is_online) track_id = self.generate_track_id(inventories[0].roomtype_id) params = {'track_id': track_id, 'data': json_encode({'list': [inventory_data]})} Log.info("push inventory roomtype {}: {}".format(inventories[0].roomtype_id, params)) if not IS_PUSH_TO_STOCK: raise gen.Return(True) url = API['STOCK'] + '/stock/update_inventory?is_async=false' r = yield AsyncHTTPClient().fetch(url, method='POST', body=urllib.urlencode(params)) Log.info("push inventory roomtype {} response {}".format(inventories[0].roomtype_id, r.body)) resp = json.loads(r.body) raise gen.Return(resp and resp['errcode'] == 0)
def post_inventory(self, inventories, is_online=1): if not inventories: return True inventory_data = self.generate_inventory_data(inventories, is_online) track_id = self.generate_track_id(inventories[0].roomtype_id) params = { 'track_id': track_id, 'data': json_encode({'list': [inventory_data]}) } Log.info("push inventory roomtype {}: {}".format( inventories[0].roomtype_id, params)) if not IS_PUSH_TO_STOCK: return True url = API['STOCK'] + '/stock/update_inventory?is_async=false' r = requests.post(url, data=params) Log.info("push inventory roomtype {} response {}".format( inventories[0].roomtype_id, r.text)) return r.status_code == 200 and r.json()['errcode'] == 0
def post_roomrate(self, merchant_id, roomrate): roomrate_datas = self.generate_roomrate_datas(merchant_id, roomrate) track_id = self.generate_track_id(roomrate.id) data = { 'track_id': track_id, 'data': json_encode({'list': roomrate_datas}) } Log.info("<<push roomrate {}>>: {}".format(roomrate.id, data)) if not IS_PUSH_TO_STOCK: raise gen.Return(True) url = API['STOCK'] + '/stock/update_room_rate?is_async=false' body = urllib.urlencode(data) r = yield AsyncHTTPClient().fetch(url, method="POST", body=body) resp = json.loads(r.body) Log.info("<<push roomrate {}>> response:{}".format( roomrate.id, r.body)) if resp and resp['errcode'] == 0: raise gen.Return(True) else: raise gen.Return(False)
def post_hotel(self, hotel_data): Log.info(u"<<POI push hotel mapping>> push request {}".format(hotel_data)) url = API['POI'] + '/api/push/ebooking/hotel/' r = requests.post(url, data=json_encode(hotel_data)) Log.info("<<POI push hotel mapping>> response {}".format(r.text))
def post_hotel(self, hotel_data): Log.info( u"<<POI push hotel mapping>> push request {}".format(hotel_data)) url = API['POI'] + '/api/push/ebooking/hotel/' r = requests.post(url, data=json_encode(hotel_data)) Log.info("<<POI push hotel mapping>> response {}".format(r.text))
def post_room(self, room_data): Log.info( u"<<POI push roomtype mapping>> push request {}".format(room_data)) url = API['POI'] + '/api/push/ebooking/room/' r = requests.post(url, data=json_encode(room_data)) Log.info("<<POI push roomtype mapping>> response {}".format(r.text))
def finish_json(self, errcode=0, errmsg=None, result=None): self.set_header("Content-Type", "application/json; charset=UTF-8") self.finish(json_encode({'errcode': errcode, 'errmsg': errmsg, 'result': result}))
def post_room(self, room_data): Log.info(u"<<POI push roomtype mapping>> push request {}".format(room_data)) url = API['POI'] + '/api/push/ebooking/room/' r = requests.post(url, data=json_encode(room_data)) Log.info("<<POI push roomtype mapping>> response {}".format(r.text))