Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add delivery_info #23

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 40 additions & 4 deletions menu/SelectProfileTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,56 @@

from config import cookies_config_path
from util.BiliRequest import BiliRequest
from util.JsonUtil import ProfileInfo
from util.JsonUtil import ProfileInfo, AddrInfo


class SelectProfileTable:
def __init__(self, master, data, max_selections, onSubmitPersons):
def __init__(self, master, data, addr_data, max_selections,onSubmitPersons,onSubmitAddr):
self.profileInfo = ProfileInfo(data)
self.addrInfo = AddrInfo(addr_data)
self.master = master
self.onSubmitPersons = onSubmitPersons
self.onSubmitAddr = onSubmitAddr
self.master.title("选人")
self.persons = self.profileInfo.get_persons()
self.addrs = self.addrInfo.get_addrs()
self.max_selections = max_selections
self.selected_indices = set()
self.addr_indices=set()

# select person
self.listbox = tk.Listbox(master, selectmode=tk.MULTIPLE, width=50)
self.listbox.grid(row=0, column=0, padx=10, pady=10, sticky=tk.W)
for person in self.persons:
name = person['name']
self.listbox.insert(tk.END, f"{name}")
self.listbox.itemconfig(tk.END, {'fg': "black"})

# select address
self.addr_listbox = tk.Listbox(master, selectmode=tk.SINGLE, width=50)
self.addr_listbox.grid(row=1, column=0, padx=10, pady=10, sticky=tk.W)
for addr in self.addrs:
name = addr['name']
self.addr_listbox.insert(tk.END, f"{name}")
self.addr_listbox.itemconfig(tk.END, {'fg': "black"})

self.detail_text = tk.Text(master, height=10, width=40)
self.detail_text.grid(row=0, column=1, padx=10, pady=10, sticky=tk.W)

self.addr_text=tk.Text(master, height=10, width=40)
self.addr_text.grid(row=1, column=1, padx=10, pady=10, sticky=tk.W)

self.submit_button = ttk.Button(master, text="提交", command=self.submit_booking)
self.submit_button.grid(row=2, column=0, columnspan=2, pady=10)

self.displayed_number_label = tk.Label(master, text="")
self.displayed_number_label.grid(row=2, column=0, pady=10)

self.listbox.bind('<<ListboxSelect>>', self.display_ticket_details)
self.addr_listbox.bind('<<ListboxSelect>>', self.display_address_details)

def display_ticket_details(self, event):

def display_ticket_details(self,event):
selected_indices = self.listbox.curselection()
if selected_indices:
self.selected_indices = set(selected_indices)
Expand All @@ -47,10 +65,26 @@ def display_ticket_details(self, event):
self.detail_text.delete(1.0, tk.END)
self.detail_text.insert(tk.END, details)

def display_address_details(self,event):
addr_indices = self.addr_listbox.curselection()
if addr_indices:
self.addr_indices = set(addr_indices)
details = ""
for index in addr_indices:
selected_ticket = self.addrs[index]
details += f"名字: {selected_ticket['name']}\n" \
f"电话: {selected_ticket['phone']}\n" \
f"地址: {selected_ticket['prov'] + selected_ticket['city'] + selected_ticket['area'] + selected_ticket['addr']}\n\n"

self.addr_text.delete(1.0, tk.END)
self.addr_text.insert(tk.END, details)

def submit_booking(self):
if len(self.selected_indices) == self.max_selections:
persons = [self.persons[index] for index in self.selected_indices]
addr=[self.addrs[index] for index in self.addr_indices]
self.onSubmitPersons(persons)
self.onSubmitAddr(addr)
self.master.destroy()
self.master.quit() # Exit the mainloop
else:
Expand All @@ -63,7 +97,9 @@ def submit_booking(self):
_request = BiliRequest(cookies_config_path=cookies_config_path)
res = _request.get(url="https://show.bilibili.com/api/ticket/buyer/list?is_default&projectId=74924")
print(res.text)
addr_res = _request.get(url="https://show.bilibili.com/api/ticket/addr/list")
print(addr_res.text)

root = tk.Tk()
app = SelectProfileTable(root, res.json(), max_selections=3)
app = SelectProfileTable(root, res.json(), addr_res.json(), max_selections=3,onSubmitPersons=lambda x: print(x))
root.mainloop()
24 changes: 17 additions & 7 deletions menu/TicketOptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,32 @@ def onSubmitTicket(buy_info):
url=f"https://show.bilibili.com/api/ticket/order/prepare?project_id={projectId}", data=token_payload)
logging.info(f"res.text: {res.text}")
token = ""
# if "token" in res.json()["data"]:
# token = res.json()["data"]["token"]
if "token" in res.json()["data"]:
token = res.json()["data"]["token"]

order_info = _request.get(
url=f"https://show.bilibili.com/api/ticket/order/confirmInfo?token={token}&voucher=&project_id={projectId}")
contact_info = order_info.json()["data"].get("contact_info", {})

logging.info(f"contact_info: {contact_info}")
ts = int(time.time()) * 1000
buyer_info = []
delivery_info = {}
res = _request.get(url=f"https://show.bilibili.com/api/ticket/buyer/list?is_default&projectId={projectId}")
print(res.text)
addr_res = _request.get(url="https://show.bilibili.com/api/ticket/addr/list")
print(addr_res.text)
root = tk.Toplevel()

def update_buyer_info(x):
nonlocal buyer_info
buyer_info = x

selectProfileTable = SelectProfileTable(root, res.json(), max_selections=buy_info["count"],
onSubmitPersons=update_buyer_info)
def update_addr_info(x):
nonlocal delivery_info
delivery_info = x[0]

selectProfileTable = SelectProfileTable(root, res.json(), addr_res.json(), max_selections=buy_info["count"],
onSubmitPersons=update_buyer_info, onSubmitAddr=update_addr_info)
root.mainloop()
# "isBuyerInfoVerified": true,
# "isBuyerValid": true
Expand All @@ -67,8 +74,11 @@ def update_buyer_info(x):
"pay_money": order_info.json()["data"].get("pay_money", ""),
"timestamp": ts,
"buyer_info": buyer_info,
"buyer": contact_info.get("username", ""),
"tel": contact_info.get("tel", "")
"buyer": buyer_info[0]["name"],
"tel": buyer_info[0]["tel"],
"deliver_info": {"name": delivery_info["name"], "tel": delivery_info["phone"], "addr_id": delivery_info["id"],
"addr": delivery_info["prov"] + delivery_info["city"] + delivery_info["area"] + delivery_info[
"addr"]}
}

logging.info(order_config)
Expand Down
7 changes: 7 additions & 0 deletions util/JsonUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,10 @@ def __init__(self, data):

def get_persons(self):
return self.personList

class AddrInfo:
def __init__(self, data):
self.addrList = data["data"]["addr_list"]

def get_addrs(self):
return self.addrList
Loading