Skip to content

Instantly share code, notes, and snippets.

@udonmai
Created July 14, 2017 04:31
Show Gist options
  • Save udonmai/c68f277845b2129a6a767b74db08ddd6 to your computer and use it in GitHub Desktop.
Save udonmai/c68f277845b2129a6a767b74db08ddd6 to your computer and use it in GitHub Desktop.
import requests
from bs4 import BeautifulSoup
import datetime
s = requests.Session()
# 51 56
place = '51'
timeSlotParam = 4
timeSlotsTable = {
'56': {
'1': '09:00~11:00',
'2': '11:30~13:30',
'3': '14:00~16:00',
'4': '16:30~18:30',
'5': '19:00~21:00'
},
'51': {
'1': '09:00~11:00',
'2': '11:30~13:30',
'3': '14:00~16:00',
'4': '16:30~18:30',
'5': '19:00~21:00'
}
}
# 1
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36'}
url = 'https://yoyaku.cultos-y.jp/shibuya-web/reserve/gin_menu'
payload = {'g_sessionid': ''}
r = s.post(url, headers=headers, data=payload)
document = r.text
soup = BeautifulSoup(document, "html.parser")
#print(document)
g_sessionid = soup.find_all(attrs={"name": "g_sessionid"})[0]['value']
JSESSIONID_1 = r.cookies['JSESSIONID']
'''
print('1')
print('g_sessionid')
print(g_sessionid)
print('JSESSIONID_1')
print(JSESSIONID_1)
#print(r.request.headers)
'''
print('#')
# 2
url = 'https://yoyaku.cultos-y.jp/shibuya-web/reserve/gin_init'
payload = {'g_sessionid': g_sessionid}
r = s.post(url, headers=headers, data=payload)
JSESSIONID_2 = r.cookies['JSESSIONID']
'''
print('2')
print('JSESSIONID_2')
print(JSESSIONID_2)
print(r.request.headers)
'''
print('#')
# 3
'''
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36',
'Cookie': 'JSESSIONID=' + JSESSIONID_2
}
'''
url = 'https://yoyaku.cultos-y.jp/shibuya-web/reserve/gin_z_group_sel_1'
payload = {
'g_sessionid': g_sessionid,
'u_genzai_idx': 0,
'g_kinonaiyo': 8
}
#cookies = dict(JSESSIONID=JSESSIONID_2)
r =s.post(url, headers=headers, data=payload)
'''
print('3')
print(r.request.headers)
document = r.text
soup = BeautifulSoup(document, "html.parser")
print(soup.title)
'''
print('#')
# 4
url = 'https://yoyaku.cultos-y.jp/shibuya-web/reserve/gin_z_dest_sel'
payload = {'g_sessionid': g_sessionid,
'checkedAll': 'false',
'g_bunruicd': 9000,
'bunruicd': 9000,
'u_genzai_idx': 1,
'g_kinonaiyo': 8,
'pageflg': 1
}
r =s.post(url, headers=headers, data=payload)
'''
print('4')
print(r.request.headers)
document = r.text
soup = BeautifulSoup(document, "html.parser")
print(soup.title)
'''
print('#')
# 5
url = 'https://yoyaku.cultos-y.jp/shibuya-web/reserve/gin_z_amenity_sel'
# basket 6010
payload = {
'g_sessionid': g_sessionid,
'riyosmk': '6010',
'u_genzai_idx': 2,
'g_kinonaiyo': 8
}
r =s.post(url, headers=headers, data=payload)
'''
print('5')
document = r.text
soup = BeautifulSoup(document, "html.parser")
print(soup.title)
'''
print('#')
# 6
url = 'https://yoyaku.cultos-y.jp/shibuya-web/reserve/gin_z_room_sel'
# higashi
payload = {
'56': {
'g_sessionid': g_sessionid,
'u_genzai_idx': 3,
'g_kinonaiyo': 8,
'g_basyocd': 56,
'g_jitubasyocd': 56,
'shisetugroup': 5,
'g_systemcd': 1,
'g_mkkbn': 2,
},
'51': {
'g_sessionid': g_sessionid,
'u_genzai_idx': 3,
'g_kinonaiyo': 8,
'g_basyocd': 51,
'g_jitubasyocd': 51,
'shisetugroup': 5,
'g_systemcd': 1,
'g_mkkbn': 2,
}
}
r =s.post(url, headers=headers, data=payload[place])
'''
print('6')
print(r.request.headers)
document = r.text
soup = BeautifulSoup(document, "html.parser")
print(soup.title)
'''
print('#')
#7
url = 'https://yoyaku.cultos-y.jp/shibuya-web/reserve/gin_z_dsp_sel'
payload = {
'56': {
'g_sessionid': g_sessionid,
'u_genzai_idx': 4,
'g_kinonaiyo': 8,
'g_kinomkkbn': 2,
'g_basyocd': 56,
'g_stgroup': 5,
'g_sisetucd': 561
},
'51': {
'g_sessionid': g_sessionid,
'u_genzai_idx': 4,
'g_kinonaiyo': 8,
'g_kinomkkbn': 2,
'g_basyocd': 51,
'g_stgroup': 5,
'g_sisetucd': 501,
}
}
r =s.post(url, headers=headers, data=payload[place])
'''
print('7')
document = r.text
soup = BeautifulSoup(document, "html.parser")
print(soup.title)
'''
print('#')
# 8
url = 'https://yoyaku.cultos-y.jp/shibuya-web/reserve/gin_z_datetime_sel_1'
tomorrow = datetime.date.today() + datetime.timedelta(days=1)
tomorrow = tomorrow.strftime("%Y%m%d")
payload = {
'g_sessionid': g_sessionid,
'u_yobi': '',
'u_yobi': '',
'u_yobi': '',
'u_yobi': '',
'u_yobi': '',
'u_yobi': '',
'u_yobi': '',
'u_yobi': '',
'ymd': tomorrow,
'u_genzai_idx':5,
'g_kinonaiyo': 8
}
r =s.post(url, headers=headers, data=payload)
'''
print('8')
print(tomorrow)
document = r.text
soup = BeautifulSoup(document, "html.parser")
print(soup.title)
'''
print('#')
# 9
url = 'https://yoyaku.cultos-y.jp/shibuya-web/reserve/gin_z_amenitytime_sel_1'
tomorrow = datetime.date.today() + datetime.timedelta(days=1)
tomorrow = tomorrow.strftime("%Y%m%d")
payload = {
'g_sessionid': g_sessionid,
'flg_sstkoma': 0,
'u_genzai_idx': 6,
'g_kinonaiyo': 8,
'showStartKoma': 1,
'showEndKoma': 7
}
r =s.post(url, headers=headers, data=payload)
print('#')
#print('9')
document = r.text
soup = BeautifulSoup(document, "html.parser")
title = soup.find_all(attrs={"class": "facilities"})[0]
print(title)
# 10
count = 10
for x in [7, 14, 21, 28, 35, 42, 49, 56, 63, 70]:
week = datetime.date.today() + datetime.timedelta(days=x)
url = 'https://yoyaku.cultos-y.jp/shibuya-web/reserve/gin_z_amenitytime_sel_1'
#print(week)
payload = {
'g_sessionid': g_sessionid,
'flg_ikou': 0,
'u_genzai_idx': 6,
'hiduke_sousa_flg': 0,
'showStartKoma': 1,
'showEndKoma': 7,
'u_hyojibi': week,
'yoyakuinfo': ''
}
r =s.post(url, headers=headers, data=payload)
#print(count)
document = r.text
soup = BeautifulSoup(document, "html.parser")
# check available
availableDate = ''
timeSlot = ''
availables = soup.find_all(attrs={"title": "O"})
for available in availables:
parent = available.parent.parent
previous_sibling = parent
while previous_sibling:
if previous_sibling.previous_sibling:
previous_sibling = previous_sibling.previous_sibling
else:
break
idx = (parent['id']).split('_')[1]
if int(idx) >= timeSlotParam:
timeSlot = timeSlotsTable[place][idx]
print(previous_sibling.string)
print(timeSlot)
count = count + 1
print('\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment