-
Notifications
You must be signed in to change notification settings - Fork 15
/
crack_tixcraft.py
85 lines (69 loc) · 2.18 KB
/
crack_tixcraft.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from argparse import ArgumentParser
from selenium import webdriver
import json
from tixcraft.picker import AreaPicker
from tixcraft.core import TixCraft
from tixcraft.utils import login
def get_args():
parser = ArgumentParser()
parser.add_argument(
"-url",
help='活動URL (例如 "https://tixcraft.com/activity/detail/19_Ann")',
dest="activity_url",
required=True,
)
parser.add_argument(
"-i", help='活動場次索引 (預設 "0")', dest="activity_index", default=0, type=int
)
parser.add_argument(
"-n", help='購買票數 (預設 "1")', dest="ticket_number", default=1, type=int
)
parser.add_argument("-an", help='區域名稱 (例如 "藍203")', dest="area_name", default="")
parser.add_argument(
"-ap", help='區域售價 (例如 "2880")', dest="area_price", default=0, type=int
)
parser.add_argument(
"-r", help='區域選取規則 ("hp" 選擇最高售價區域 | "lp" 選擇最低售價區域)', dest="rule", default=""
)
return parser.parse_args()
def convert_rule(rule):
rules = {
"hp": AreaPicker.HIGHEST_PRICE,
"lp": AreaPicker.LOWEST_PRICE,
"r": AreaPicker.RANDOM,
"sn": AreaPicker.SPECIFIC_NAME,
"sp": AreaPicker.SPECIFIC_PRICE,
}
try:
rule = rules[rule]
except KeyError:
rule = AreaPicker.RANDOM
return rule
def save_cookie(cookies):
with open("session.json", "w") as f:
json.dump(cookies, f)
def load_cookies():
try:
with open("session.json") as f:
cookies = json.load(f)
except FileNotFoundError:
cookies = None
return cookies
def main():
args = get_args()
activity_url = args.activity_url
setting = {
"activity_index": args.activity_index,
"ticket_number": args.ticket_number,
"area_name": args.area_name,
"area_price": args.area_price,
"rule": convert_rule(args.rule),
}
cookies = load_cookies()
if cookies is None:
cookies = login()
save_cookie(cookies)
tixcraft = TixCraft(activity_url, cookies, **setting)
tixcraft.run()
if __name__ == "__main__":
main()