can choose store

This commit is contained in:
2022-05-11 16:25:37 +02:00
parent 2d73d58f62
commit aedea57fbd
3 changed files with 81 additions and 9 deletions
+63
View File
@@ -0,0 +1,63 @@
import PySimpleGUI as sg
# First the window layout in 2 columns
from main import start_book
KEY_CHOOSE_STORE = "CHOOSE_STORE"
KEY_START_NUMBER = "KEY_START_NUMBER"
KEY_END_NUMBER = "KEY_END_NUMBER"
KEY_MAX_WORKERS = "KEY_MAX_WORKERS"
KEY_RANDOM = "KEY_RANDOM"
KEY_FAUBOURG = "KEY_FAUBOURG"
KEY_GEORGE = "KEY_GEORGE"
KEY_SEVRES = "KEY_SEVRES"
GROUP_STORE = "STORE"
file_list_column = [
[sg.Text('请输入联系人表的起始和结束行')],
[sg.Text('起始行', size=(15, 1)), sg.InputText(tooltip="起始行", key=KEY_START_NUMBER)],
[sg.Text('结束行', size=(15, 1)), sg.InputText(tooltip="结束行", key=KEY_END_NUMBER)],
[sg.Text('并发数', size=(15, 1)), sg.InputText(tooltip="结束行", key=KEY_MAX_WORKERS, default_text=10)],
[sg.Submit(button_text="运行", key="submit")]
]
# For now will only show the name of the file that was chosen
settings_column = [
[sg.Text("目标商店")],
[sg.Radio('随机', group_id=GROUP_STORE, key=KEY_RANDOM, default=True)],
[sg.Radio('Hermès Faubourg Saint-Honoré', group_id=GROUP_STORE, key=KEY_FAUBOURG, default=False)],
[sg.Radio('Hermès George V', group_id=GROUP_STORE, key=KEY_GEORGE, default=False)],
[sg.Radio('Hermès Sèvres', group_id=GROUP_STORE, key=KEY_SEVRES, default=False)]
]
# ----- Full layout -----
layout = [
[
sg.Column(file_list_column),
sg.Column(settings_column)
]
]
window = sg.Window("爱马仕约会", layout)
while True:
event, values = window.read()
print(event)
print(values)
if event == "submit":
try:
start_line = int(values[KEY_START_NUMBER])
end_line = int(values[KEY_END_NUMBER])
max_workers = int(values[KEY_MAX_WORKERS])
store_type = 0
if values[KEY_FAUBOURG]:
store_type = 1
elif values[KEY_GEORGE]:
store_type = 2
elif values[KEY_SEVRES]:
store_type = 3
start_book(start_line, end_line, store_choose_state=store_type, max_workers=max_workers)
except Exception as error:
print("Not Integer: ")
print(error)
elif event == "Exit" or event == sg.WIN_CLOSED:
break
+5 -6
View File
@@ -14,17 +14,16 @@ logger = logging.getLogger()
logger.addHandler(logging.StreamHandler(stream=sys.stdout))
def start_book(start_number, end_number, store=0):
def start_book(start_number, end_number, store_choose_state=0, max_workers=10):
# read the contact, and contact the 2 objects together
excel_reader = ExcelHelper()
contacts = excel_reader.read_contacts()[start_number - 1: end_number]
print(contacts)
with ThreadPoolExecutor(max_workers=1) as executor:
logger.info(contacts)
with ThreadPoolExecutor(max_workers=max_workers) as executor:
for contact in contacts:
proxy = get_proxy(contact.phone)
commandor = CommandorPage(contact, store_type=store)
# start the task in thread
executor.submit(commandor.start_page, proxy)
executor.submit(CommandorPage(contact, store_type=store_choose_state).start_page, proxy)
def get_proxy(phone_number):
@@ -41,4 +40,4 @@ def get_proxy(phone_number):
if __name__ == '__main__':
# 修改联系人行,结束联系人行 第三个参数store等于0的时候是随机,传入1的时候是总店
start_book(1, 1, store=0)
start_book(1, 1, store_choose_state=0)
+13 -3
View File
@@ -47,6 +47,15 @@ class CommandorPage:
self.logger = logging.getLogger("CommandorPage")
self.is_finished = False
self.contact = contact
# 0: random
# 1: faubourg
# 2: George
# 3: Sèvres
self.store_map = {
1: "faubourg",
2: "georgev",
3: "sevres"
}
self.store_type = store_type
def on_success(self, result: ReserveResultPojo):
@@ -159,10 +168,11 @@ class CommandorPage:
document.getElementById("phone_country").focus();
document.getElementById("phone_country").value = \"FR\" }""")
else:
self.page.evaluate("""()=>{
document.getElementById("prefer").value = \"faubourg\";
store_to_choose = self.store_map[self.store_type]
self.page.evaluate("""(store_to_choose)=>{
document.getElementById("prefer").value = store_to_choose;
document.getElementById("phone_country").focus();
document.getElementById("phone_country").value = \"FR\" }""")
document.getElementById("phone_country").value = \"FR\" }""", store_to_choose)
except Exception as error:
self.logger.error(error)