#coding=utf-8
import requests,re,datetime,json,sys
reload(sys)
sys.setdefaultencoding("utf-8")
murl = 'https://m.shangri-la.com/v1/mobile?__c=12360172354647'
traveldate = "2019-12-20"
fromdate = datetime.datetime.strptime(traveldate, '%Y-%m-%d')
todate = (fromdate+datetime.timedelta(days=1)).strftime("%Y-%m-%d")
#def getRooms(city="包头",dates="2019-12-20"):
def getRooms(city,fromdate,todate):
headers={}
headers['Content-Type']='application/x-sl-app;ext=0-0-0'
headers['Origin']='https://m.shangri-la.com/v1/mobile?__c=12360172354647'
headers['User-Agent']='Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1'
headers['Referer']='https://m.shangri-la.com/v1/mobile?__c=12360172354647'
payload = ('{"service":"hotelEntryService.searchHotel(hotelEntryQuery)","query":{"hotelEntryQuery":{"adultNum":1,"bizType":"SPECIAL_ROOM_SUITE","childNum":0,"checkOutDate":"%s","roomNum":1,"currency":"CNY","specialCodeType":"","type":"CITY","dest":"%s","checkInDate":"%s","specialCode":""}},"context":{"appVersion":"2.0.18","os":"","timeZone":"+8:00","packageType":"production","platform":"ANDROID/MW","vendor":"","lang":"Chinese","net":"","brand":"","sh":375,"sw":667,"uuid":"MW-||1575122619175","unionId":null,"mac":"","imei":"","carrier":"","ip":"","downloadChannel":"","source":"M_WEBSITE","dvid":"dw-c770ecf6-62f6-4640-9e69-a79f12c6eac4"},"user":{},"mfa":{"accessTicket":""},"header":{"X-Sl-Service":"hotelEntryService.searchHotel(hotelEntryQuery)","Content-Type":"application/x-sl-app;ext=0-0-0"}}')%(todate,city,fromdate)
# payload = '{"service":"hotelDetailService.queryHotelDetail(query)","query":{"query":{"adultNum":1,"bizType":"SPECIAL_ROOM_SUITE","childNum":0,"checkOutDate":"2019-12-21","roomNum":1,"currency":"CNY","specialCodeType":"","type":"CITY","dest":"%s","checkInDate":"%s","specialCode":"","hotelCode":"SLBT"}},"context":{"appVersion":"2.0.18","os":"","timeZone":"+8:00","packageType":"production","platform":"ANDROID/MW","vendor":"","lang":"Chinese","net":"","brand":"","sh":375,"sw":667,"uuid":"MW-||1575122619175","unionId":0,"mac":"","imei":"","carrier":"","ip":"","downloadChannel":"","source":"M_WEBSITE","dvid":"dw-c770ecf6-62f6-4640-9e69-a79f12c6eac4"},"user":{},"mfa":{"accessTicket":""},"header":{"X-Sl-Service":"hotelDetailService.queryHotelDetail(query)","Content-Type":"application/x-sl-app;ext=0-0-0"}}'%(city,dates)
#payload["location"] = {"location":"11"}
#print(json.dumps(payload))
resp = requests.post(murl,data=payload,headers=headers)
results = json.loads(resp.content)
#print(resp.content)
if "hotelList" in resp.content:
hotelList = results['data']['hotelList']
for hotel in hotelList:
name = hotel['hotelName']
amount = hotel['price']['amount']
redeemPoints = hotel['redeemPoints']
print(("%s - %s - %s - %s")%(name,amount,redeemPoints,str(int(amount)*1000/int(redeemPoints))))
elif "hotelDetail" in resp.content:
hotel = results['data']['hotelDetail']
name = hotel['name']
amount = hotel['rooms'][0]['roomRate']['originRate']['price']['money']['amount']
redeemPoints = hotel['rooms'][0]['roomRate']['originRate']['redeemPoints']
print(("%s - %s - %s - %s")%(name,amount,redeemPoints,str(int(amount)*1000/int(redeemPoints))))
#print(resp.content)
#getRooms("包头","2019-12-20")
def getallCity():
headers={}
headers['Content-Type']='application/x-sl-app;ext=0-0-0'
headers['Origin']='https://m.shangri-la.com/v1/mobile?__c=12360172354647'
headers['User-Agent']='Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1'
headers['Referer']='https://m.shangri-la.com/v1/mobile?__c=12360172354647'
payload = '{"service":"configService.checkConfigs(query)","query":{"query":{"checkList":[{"version":0,"file":"HotCity.json"},{"version":0,"file":"cityList.json"},{"version":0,"file":"mfaVerifyAlert.json"}],"appCode":"mobile","all":false}},"context":{"appVersion":"2.0.18","os":"","timeZone":"+8:00","packageType":"production","platform":"ANDROID/MW","vendor":"","lang":"Chinese","net":"","brand":"","sh":375,"sw":667,"uuid":"MW-||1575122619175","unionId":null,"mac":"","imei":"","carrier":"","ip":"","downloadChannel":"","source":"M_WEBSITE","dvid":"dw-c770ecf6-62f6-4640-9e69-a79f12c6eac4"},"user":{},"mfa":{"accessTicket":""},"header":{"X-Sl-Service":"configService.checkConfigs(query)","Content-Type":"application/x-sl-app;ext=0-0-0"}}'
#payload["location"] = {"location":"11"}
#print(json.dumps(payload))
resp = requests.post(murl,data=payload,headers=headers)
results = json.loads(resp.content)
#print(resp.content)
citylist = json.loads(results['data']['configs'][1]['dataContent'])
for item in citylist["CN"]:
for cityname in item['citydata']:
cname = cityname.split("|")[0].strip()
try:
getRooms(cname.encode("utf8"),fromdate,todate)
except:
print("Error while:" + cname)
getallCity()