Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
MakiNaruto committed May 24, 2022
2 parents 220b86b + a41c28b commit a3b299b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea/

Pipfile
37 changes: 20 additions & 17 deletions Automatic_ticket_purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,17 @@ def __init__(self):
# 登录信息
self.login_cookies = {}
self.session = session()
self.login_id: str = 'account' # 大麦网登录账户名
self.login_password: str = 'password' # 大麦网登录密码
self.login_id: str = 'account' # 大麦网登录账户名
self.login_password: str = 'password' # 大麦网登录密码
# 以下为抢票必须的参数
self.item_id: int = 610820299671 # 商品id
self.viewer: list = ['viewer1'] # 在大麦网已填写的观影人
self.buy_nums: int = 1 # 购买影票数量, 需与观影人数量一致
self.ticket_price: int = 180 # 购买指定票价
self.item_id: int = 610820299671 # 商品id
self.viewer: list = ['viewer1'] # 在大麦网已填写的观影人
self.buy_nums: int = 1 # 购买影票数量, 需与观影人数量一致
self.ticket_price: int = 180 # 购买指定票价

def step1_get_order_info(self, item_id, commodity_param, ticket_price=None):
"""
获取点击购买所必须的参数信息
:param item_id: 商品id
:param commodity_param: 获取商品购买信息必须的参数
:param ticket_price: 购买指定价位的票
Expand Down Expand Up @@ -72,7 +71,6 @@ def step1_get_order_info(self, item_id, commodity_param, ticket_price=None):
def step2_click_buy_now(self, ex_params, sku_info):
"""
点击立即购买
:param ex_params: 点击立即购买按钮所发送请求的必须参数
:param sku_info: 购买指定商品信息及数量信息
:return:
Expand Down Expand Up @@ -146,7 +144,8 @@ def step2_click_confirm_select_seats(self, project_id, perform_id, seat_info, sk
'spm': 'a2oeg.selectseat.bottom.dbuy',
}

response = requests.get('https://buy.damai.cn/orderConfirm', params=params, cookies=self.login_cookies, headers=headers)
response = requests.get('https://buy.damai.cn/orderConfirm', params=params, cookies=self.login_cookies,
headers=headers)
if response.status_code == 200:
result = re.search('window.__INIT_DATA__[\s\S]*?};', response.text)
self.login_cookies.update(self.session.cookies)
Expand All @@ -162,7 +161,6 @@ def step2_click_confirm_select_seats(self, project_id, perform_id, seat_info, sk
def step3_submit_order(self, submit_order_info, viewer, seat_info=None):
"""
提交订单所需参数信息
:param submit_order_info: 最终确认订单所需的所有信息。
:param viewer: 指定观演人进行购票
:param seat_info: 座位id
Expand Down Expand Up @@ -190,9 +188,9 @@ def step3_submit_order(self, submit_order_info, viewer, seat_info=None):
('submitref', 'undefined'),
)
dm_viewer_pc = str([k for k, v in submit_order_info.get('data').items()])
dm_viewer_pc_id = re.search('dmViewerPC_[0-9]*', dm_viewer_pc).group()
if dm_viewer_pc_id:

dm_viewer_pc_id_search = re.search('dmViewerPC_[0-9]*', dm_viewer_pc)
if dm_viewer_pc_id_search:
dm_viewer_pc_id = dm_viewer_pc_id_search.group() # 获取到观演人的 key
user_list = submit_order_info['data'][dm_viewer_pc_id]['fields']['dmViewerList']
all_available_user = [name.get('viewerName') for name in user_list]
if len(set(viewer).intersection(set(all_available_user))) != len(viewer):
Expand All @@ -211,6 +209,8 @@ def step3_submit_order(self, submit_order_info, viewer, seat_info=None):
if user.get('viewerName') in viewer:
user['seatId'] = seat_info[seat_index]
seat_index += 1
else:
print("该场次不需要指定观演人")

submit_order_info = json.dumps(submit_order_info)
response = self.session.post('https://buy.damai.cn/multi/trans/createOrder',
Expand Down Expand Up @@ -265,7 +265,8 @@ def run(self):
elif ticket_sku_status == '选座购买':
# 获取选座购买必备的数据信息。
city_id, project_id, item_id, perform_id = tools.get_select_seat_params(self.item_id)
stand_id, seat_price_list = tools.get_seat_dynamic_info(self.login_cookies, project_id, item_id, perform_id)
stand_id, seat_price_list = tools.get_seat_dynamic_info(self.login_cookies, project_id, item_id,
perform_id)
api_address = tools.get_select_seat_api(self.login_cookies, perform_id, city_id)
buy_serial_number = '{}_{}_{}'.format(self.item_id, self.buy_nums, sku_id)
api_address += str(stand_id) + '.json'
Expand All @@ -275,7 +276,8 @@ def run(self):
# 获取全部的座位信息
all_seats_info = json.loads(response.text)
# 获取可售的座位信息
valuable_info = tools.get_valuable_seat_id(self.login_cookies, project_id, perform_id, city_id, stand_id)
valuable_info = tools.get_valuable_seat_id(self.login_cookies, project_id, perform_id, city_id,
stand_id)
# 获取 指定抢票价格的 sku_id, price_id
sku_id, price_id = None, None
for sku_info in seat_price_list:
Expand All @@ -295,7 +297,8 @@ def run(self):
valuable_seat = tools.format_valuable_seatid(all_seats_info, valuable_info, price_id)
# 挑选座位
seat_info = tools.pick_seat(valuable_seat, stand_id, self.buy_nums)
submit_order_info = self.step2_click_confirm_select_seats(project_id, perform_id, seat_info, buy_serial_number)
submit_order_info = self.step2_click_confirm_select_seats(project_id, perform_id, seat_info,
buy_serial_number)
break
if not buy_serial_number or not submit_order_info:
print('-' * 10, '获取购票所需信息失败', '-' * 10)
Expand All @@ -309,4 +312,4 @@ def run(self):
help='account: account login, QR: Scan QR code login')
args = parser.parse_args()
a = DaMaiTicket()
a.run()
a.run()

0 comments on commit a3b299b

Please sign in to comment.