Skip to content

Commit

Permalink
单个单元格限制提醒
Browse files Browse the repository at this point in the history
  • Loading branch information
NaiboWang committed Jul 25, 2023
1 parent 528ae7a commit 145c766
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 30 deletions.
21 changes: 21 additions & 0 deletions ElectronJS/src/taskGrid/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ ws.onmessage = function(evt) {
}
};

function changeOutputFormat(para){
try{
for(let i=0;i<para["parameters"].length;i++) {
let exampleValue = para["parameters"][i]["exampleValues"][0]["value"];
let len = exampleValue.length;
if (len > 20000) {
if($("#outputFormat").val() == "xlsx") {
$("#outputFormat").val("csv"); //如果有一个参数的示例值长度超过20000,就默认输出为csv
showInfo(LANG("示例值长度超过16000,超出Excel单个单元格存储限制,已自动切换保存为csv格式。", "The length of the example value exceeds 16000, and the csv save format has been automatically switched."));
}
break;
}
}
} catch(e){
console.log(e);
}
}

function changeGetDataParameters(msg, i) {
msg["parameters"][i]["default"] = ""; //找不到元素时候的默认值
msg["parameters"][i]["paraType"] = "text"; //参数类型
Expand Down Expand Up @@ -82,16 +100,19 @@ function handleAddElement(msg) {
changeGetDataParameters(msg, i);
app._data["nowNode"]["parameters"]["paras"].push(msg["parameters"][i]);
}
changeOutputFormat(msg);
app._data.paras.parameters = app._data["nowNode"]["parameters"]["paras"];
setTimeout(function(){$("#app > div.elements > div.toolkitcontain > table.toolkittb4 > tbody > tr:last-child")[0].scrollIntoView(false); //滚动到底部
}, 200);
} else {
addElement(3, msg);
changeOutputFormat(msg);
}
notifyParameterNum(msg["parameters"].length); //通知浏览器端参数的个数变化
} else if (msg["type"] == "multiCollectWithPattern") {
addElement(8, msg);
addElement(3, msg);
changeOutputFormat(msg);
notifyParameterNum(msg["parameters"].length); //通知浏览器端参数的个数变化
} else if(msg["type"] == "GetCookies"){
for(let node of nodeList){
Expand Down
1 change: 1 addition & 0 deletions ElectronJS/tasks/202.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ExecuteStage/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"justMyCode": false,
// "args": ["--id", "[7]", "--read_type", "remote", "--headless", "0"]
// "args": ["--id", "[9]", "--read_type", "remote", "--headless", "0", "--saved_file_name", "YOUTUBE"]
"args": ["--id", "[16]", "--headless", "0", "--user_data", "1", "--keyboard", "0"]
"args": ["--id", "[85]", "--headless", "0", "--user_data", "1", "--keyboard", "0"]
}
]
}
64 changes: 35 additions & 29 deletions ExecuteStage/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,34 +101,39 @@ def download_image(browser, url, save_directory):
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
}
if is_valid_url(url):
# 发送 GET 请求获取图片数据
response = requests.get(url, headers=headers)

# 检查响应状态码是否为成功状态
if response.status_code == requests.codes.ok:
# 提取文件名
file_name = url.split('/')[-1].split("?")[0]

# 生成唯一的新文件名
new_file_name = file_name + '_' + \
str(uuid.uuid4()) + '_' + file_name

# 构建保存路径
save_path = os.path.join(save_directory, new_file_name)

# 保存图片到本地
with open(save_path, 'wb') as file:
file.write(response.content)

browser.print_and_log("图片已成功下载到:", save_path)
browser.print_and_log("The image has been successfully downloaded to:", save_path)
else:
browser.print_and_log("下载图片失败,请检查此图片链接是否有效:", url)
browser.print_and_log(
"Failed to download image, please check if this image link is valid:", url)
try:
# 发送 GET 请求获取图片数据
response = requests.get(url, headers=headers)

# 检查响应状态码是否为成功状态
if response.status_code == requests.codes.ok:
# 提取文件名
file_name = url.split('/')[-1].split("?")[0]

# 生成唯一的新文件名
new_file_name = file_name + '_' + \
str(uuid.uuid4()) + '_' + file_name

# 构建保存路径
save_path = os.path.join(save_directory, new_file_name)

# 保存图片到本地
with open(save_path, 'wb') as file:
file.write(response.content)

browser.print_and_log("图片已成功下载到:", save_path)
browser.print_and_log(
"The image has been successfully downloaded to:", save_path)
else:
browser.print_and_log("下载图片失败,请检查此图片链接是否有效:", url)
browser.print_and_log(
"Failed to download image, please check if this image link is valid:", url)
except Exception as e:
browser.print_and_log("下载图片失败|Error downloading image: ", e)
else:
browser.print_and_log("下载图片失败,请检查此图片链接是否有效:", url)
browser.print_and_log("Failed to download image, please check if this image link is valid:", url)
browser.print_and_log(
"Failed to download image, please check if this image link is valid:", url)


def get_output_code(output):
Expand Down Expand Up @@ -201,9 +206,9 @@ def write_to_json(file_name, data, types, record, keys):
except:
line[i] = 0.0
if record[i]:
to_write.update({keys[i]: line[i]})
to_write.update({keys[i]: line[i]})
data_to_write.append(to_write)

try:
# read data from JSON
with open(file_name, 'r', encoding='utf-8') as f:
Expand All @@ -212,11 +217,12 @@ def write_to_json(file_name, data, types, record, keys):
json_data = []

json_data.extend(data_to_write)

# write data to JSON
with open(file_name, 'w', encoding='utf-8') as f:
json.dump(json_data, f, ensure_ascii=False)


def write_to_excel(file_name, data, types, record):
first = False
if os.path.exists(file_name):
Expand Down

0 comments on commit 145c766

Please sign in to comment.