minor fixes
This commit is contained in:
7
.gitignore
vendored
7
.gitignore
vendored
@@ -1,5 +1,6 @@
|
||||
.venv/
|
||||
.vscode/
|
||||
.workbooks/
|
||||
/.venv
|
||||
/.vscode
|
||||
/.workbooks
|
||||
*.bat
|
||||
*.xlsx
|
||||
*.xml
|
||||
47
销售订单自动导入.py
47
销售订单自动导入.py
@@ -87,7 +87,7 @@ def main(workbook=None):
|
||||
|
||||
time.sleep(args.interval) #1
|
||||
|
||||
if data.tag == 'nil-classes': break
|
||||
if data.tag in ['nil-classes', 'hash']: break
|
||||
else: index += 1
|
||||
|
||||
if root is None: root = data
|
||||
@@ -260,7 +260,10 @@ def main(workbook=None):
|
||||
print('[信息] 正在启动自动化程序')
|
||||
|
||||
try:
|
||||
driver = webdriver.Chrome()
|
||||
opts = webdriver.ChromeOptions()
|
||||
opts.add_experimental_option("excludeSwitches", ["enable-logging"])
|
||||
|
||||
driver = webdriver.Chrome(opts)
|
||||
driver.set_page_load_timeout(args.timeout)
|
||||
except Exception as e:
|
||||
print(f'[!!!!] 初始化时发生了错误:{e}')
|
||||
@@ -312,18 +315,19 @@ def main(workbook=None):
|
||||
except Exception as e:
|
||||
print(f'[!!!!] 登录网页时发生了错误:{e}')
|
||||
return 81
|
||||
else:
|
||||
print("[警告] 未提供有效登录凭证")
|
||||
key = input('[????] 请确认登录状态:已登录 (Y) / 取消操作 (N): ')
|
||||
if key in ['Y', 'y']:
|
||||
print('[信息] 已确认操作')
|
||||
else:
|
||||
print('[信息] 已取消操作')
|
||||
return 0
|
||||
|
||||
print("[信息] 正在检测登录状态...")
|
||||
while True:
|
||||
try:
|
||||
driver.find_element(By.ID, 'container')
|
||||
print("[信息] 已登录")
|
||||
break
|
||||
except:
|
||||
time.sleep(args.interval) #4
|
||||
|
||||
try:
|
||||
locate(".layout-sidebar ul li:nth-child(10) div div").click()
|
||||
locate(".layout-sidebar .layout-second-menu li:nth-child(3) a").click()
|
||||
locate(".layout-sidebar ul li.list-none.cpq div div").click()
|
||||
locate(".layout-sidebar .layout-second-menu li.order a").click()
|
||||
locate(".list-header-top button.okki-dropdown-trigger").click()
|
||||
locate(".okki-dropdown-content button").click()
|
||||
driver.switch_to.window(driver.window_handles[1])
|
||||
@@ -333,7 +337,7 @@ def main(workbook=None):
|
||||
|
||||
# 状态菜单映射
|
||||
status = { 'draft': 1, 'final': 6 }
|
||||
time.sleep(args.interval) #4
|
||||
time.sleep(args.interval) #5
|
||||
|
||||
try:
|
||||
# 变更状态
|
||||
@@ -351,7 +355,7 @@ def main(workbook=None):
|
||||
print(f'[!!!!] 上传文件时发生了错误:{e}')
|
||||
return 83
|
||||
|
||||
time.sleep(args.interval) #5
|
||||
time.sleep(args.interval) #6
|
||||
|
||||
try:
|
||||
# 等待订单录入
|
||||
@@ -367,7 +371,7 @@ def main(workbook=None):
|
||||
return 84
|
||||
|
||||
# 设置每页显示记录数
|
||||
time.sleep(args.interval) #6
|
||||
time.sleep(args.interval) #7
|
||||
url = driver.current_url
|
||||
param = f'%22page_size%22%3A{args.per_page}'
|
||||
|
||||
@@ -381,11 +385,11 @@ def main(workbook=None):
|
||||
# 等待页面加载
|
||||
wait = WebDriverWait(driver, timeout=args.timeout)
|
||||
wait.until(lambda x: 'nprogress-busy' not in x.find_element(By.TAG_NAME, 'html').get_attribute('class'))
|
||||
time.sleep(args.interval) #7
|
||||
time.sleep(args.interval) #8
|
||||
|
||||
for idx in range(args.per_page):
|
||||
try:
|
||||
links = driver.find_elements(By.CSS_SELECTOR, ".list-frame-table .virtual-list-os-target .row-items .cell[data-cci='1'] a")
|
||||
links = driver.find_elements(By.CSS_SELECTOR, ".list-frame-table .row-items .cell[data-cci='1'] a")
|
||||
element = links[idx]
|
||||
except Exception as e:
|
||||
print(f'[警告] 未找到记录: {e}')
|
||||
@@ -422,7 +426,7 @@ def main(workbook=None):
|
||||
|
||||
# 编辑运费
|
||||
try:
|
||||
wrapper = locate(".order-edit-product-wrapper .virtual-list-os-target .row-items", condition=None)
|
||||
wrapper = locate(".order-edit-product-wrapper .row-items", condition=None)
|
||||
positions = lookup(number, '产品型号', workbook).unwrap()
|
||||
index = 0
|
||||
count = positions.count('port')
|
||||
@@ -459,7 +463,7 @@ def main(workbook=None):
|
||||
button = locate(".order-edit-footer button.okki-btn-primary", condition=None)
|
||||
driver.execute_script("arguments[0].click();", button)
|
||||
|
||||
time.sleep(args.interval) #8
|
||||
time.sleep(args.interval) #9
|
||||
print(f"[信息] {number}: 修改完成")
|
||||
modified.append(number)
|
||||
|
||||
@@ -513,8 +517,9 @@ class FieldArray[K, V]:
|
||||
|
||||
def newrow(self, padding=None):
|
||||
for array in self.map.values():
|
||||
if len(array) <= self.index:
|
||||
array.insert(self.index, padding)
|
||||
limit = len(array) - 1
|
||||
delta = self.index - limit
|
||||
array.extend([ padding for _ in range(delta) ])
|
||||
self.index += 1
|
||||
|
||||
class Result:
|
||||
|
||||
Reference in New Issue
Block a user