|
|
|
@ -21,8 +21,9 @@ from cookie import get_cookie
|
|
|
|
|
logger.add("./data/log/{time}.log")
|
|
|
|
|
|
|
|
|
|
# seat data
|
|
|
|
|
COOKIE, USERNAME, PASSWORD, HEADLESS, PROXY = "", "", "", "", ""
|
|
|
|
|
COOKIE, USERNAME, PASSWORD, HEADLESS, PROXY, SEATS_SPEC = "", "", "", "", "", ""
|
|
|
|
|
SEATS_IGNORE = []
|
|
|
|
|
COOKIE_TIME = time.time()
|
|
|
|
|
with open("./data/able_d1.json", "r") as f:
|
|
|
|
|
able_d1 = json.load(f)
|
|
|
|
|
with open("./data/able_d2.json", "r") as f:
|
|
|
|
@ -127,7 +128,8 @@ async def search_seats(seats):
|
|
|
|
|
for k, l in able_d1.items():
|
|
|
|
|
for seat in l:
|
|
|
|
|
seat_id = str(seat["logicalSeatId"])
|
|
|
|
|
if "FLOOR" in seat['mapInfo'] and not sold_d1[seat_id]:
|
|
|
|
|
if not "FLOOR" in seat['mapInfo'] or sold_d1[seat_id]: continue
|
|
|
|
|
if int(seat["mapInfo"].split()[3][:-1]) >= 8: continue
|
|
|
|
|
if not seat_id in SEATS_IGNORE:
|
|
|
|
|
logger.success(f"发现内场票:d1 {seat['mapInfo']} {seat_id}")
|
|
|
|
|
seats[1].append(seat)
|
|
|
|
@ -136,7 +138,8 @@ async def search_seats(seats):
|
|
|
|
|
for k, l in able_d2.items():
|
|
|
|
|
for seat in l:
|
|
|
|
|
seat_id = str(seat["logicalSeatId"])
|
|
|
|
|
if "FLOOR" in seat['mapInfo'] and not sold_d2[seat_id]:
|
|
|
|
|
if not "FLOOR" in seat['mapInfo'] or sold_d2[seat_id]: continue
|
|
|
|
|
if int(seat["mapInfo"].split()[3][:-1]) >= 8: continue
|
|
|
|
|
if not seat_id in SEATS_IGNORE:
|
|
|
|
|
logger.success(f"发现内场票:d2 {seat['mapInfo']} {seat_id}")
|
|
|
|
|
seats[2].append(seat)
|
|
|
|
@ -168,7 +171,7 @@ def parse_seat(seat):
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async def lock_ticket(day, seats):
|
|
|
|
|
global COOKIE
|
|
|
|
|
global COOKIE, COOKIE_TIME
|
|
|
|
|
if not seats: return
|
|
|
|
|
if len(seats) > 4: seats = seats[:4]
|
|
|
|
|
day_code = 552446605 if day == 1 else 1740993756
|
|
|
|
@ -222,6 +225,7 @@ async def lock_ticket(day, seats):
|
|
|
|
|
logger.error(msg)
|
|
|
|
|
except:
|
|
|
|
|
logger.critical(f"锁票失败!可能是 cookie 过期了!正在尝试更新 cookie!")
|
|
|
|
|
if time.time() - COOKIE_TIME > 60:
|
|
|
|
|
update_cookie()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -229,7 +233,7 @@ async def lock_ticket(day, seats):
|
|
|
|
|
|
|
|
|
|
# cookie
|
|
|
|
|
def update_cookie():
|
|
|
|
|
global COOKIE, USERNAME, PASSWORD, HEADLESS
|
|
|
|
|
global COOKIE, USERNAME, PASSWORD, HEADLESS, COOKIE_TIME
|
|
|
|
|
for i in range(5):
|
|
|
|
|
COOKIE = get_cookie(USERNAME, PASSWORD, HEADLESS)
|
|
|
|
|
if COOKIE:
|
|
|
|
@ -239,6 +243,7 @@ def update_cookie():
|
|
|
|
|
with open("./conf.ini", 'w', encoding="utf8") as f:
|
|
|
|
|
config.write(f)
|
|
|
|
|
logger.info("cookie 更新成功!")
|
|
|
|
|
COOKIE_TIME = time.time()
|
|
|
|
|
return
|
|
|
|
|
logger.critical("登陆失败,无法获取 cookie!")
|
|
|
|
|
os.system("pause")
|
|
|
|
@ -249,6 +254,7 @@ def update_cookie():
|
|
|
|
|
|
|
|
|
|
# main loop state machine
|
|
|
|
|
async def loop(interval1, interval2, seats):
|
|
|
|
|
global SEATS_SPEC
|
|
|
|
|
while True:
|
|
|
|
|
if not (seats[1] or seats[2]):
|
|
|
|
|
t = time.time()
|
|
|
|
@ -265,9 +271,14 @@ async def loop(interval1, interval2, seats):
|
|
|
|
|
await asyncio.sleep(interval1 / 1000)
|
|
|
|
|
else:
|
|
|
|
|
event_loop = asyncio.get_event_loop()
|
|
|
|
|
t = time.time()
|
|
|
|
|
while True:
|
|
|
|
|
event_loop.create_task(lock_ticket(1, seats[1]))
|
|
|
|
|
event_loop.create_task(lock_ticket(2, seats[2]))
|
|
|
|
|
if not SEATS_SPEC and time.time() - t > 30:
|
|
|
|
|
seats[1].clear()
|
|
|
|
|
seats[2].clear()
|
|
|
|
|
break
|
|
|
|
|
if not (seats[1] or seats[2]):
|
|
|
|
|
break
|
|
|
|
|
else:
|
|
|
|
@ -293,8 +304,8 @@ if __name__ == "__main__":
|
|
|
|
|
PROXY = config.get("conf", "proxy") or None
|
|
|
|
|
interval1 = int(config.get("conf", "interval1") or 10000)
|
|
|
|
|
interval2 = int(config.get("conf", "interval2") or 1000)
|
|
|
|
|
seats_str = config.get("seat", "seats")
|
|
|
|
|
seats_list = seats_str.split(",") if seats_str else []
|
|
|
|
|
SEATS_SPEC = config.get("seat", "seats")
|
|
|
|
|
seats_list = SEATS_SPEC.split(",") if SEATS_SPEC else []
|
|
|
|
|
ignore_list = config.get("seat", "ignore").split(",")
|
|
|
|
|
logger.info(f"cookie = {COOKIE[:50]}...")
|
|
|
|
|
logger.info(f"proxy = {PROXY}")
|
|
|
|
|