harbor run -t openthoughts/tasktrove-exp-rpt-crosscodeeval-java-crosscodeeval-java-0987harbor download openthoughts/tasktrove-exp-rpt-crosscodeeval-java-crosscodeeval-java-0987solution file
package com.github.kingschan1204.easycrawl.task;
import com.github.kingschan1204.easycrawl.core.agent.WebAgent;
import com.github.kingschan1204.easycrawl.helper.http.UrlHelper;
import com.github.kingschan1204.easycrawl.helper.json.JsonHelper;
import com.github.kingschan1204.easycrawl.helper.validation.Assert;
import lombok.extern.slf4j.Slf4j;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.function.Function;
@Slf4j
public class EasyCrawl<R> {
private WebAgent webAgent;
private Function<WebAgent, R> parserFunction;
public EasyCrawl<R> webAgent(WebAgent webAgent) {
this.webAgent = webAgent;
return this;
}
// public static EasyCrawlNew of(WebAgentNew webAgent){
// return new EasyCrawlNew(webAgent);
// }
public EasyCrawl<R> analyze(Function<WebAgent, R> parserFunction) {
this.parserFunction = parserFunction;
return this;
}
public R execute() {
return execute(null);
}
public R execute(Map<String, Object> map) {
Assert.notNull(webAgent, "agent对象不能为空!");
Assert.notNull(parserFunction, "解析函数不能为空!");
R result;
CompletableFuture<R> cf = CompletableFuture.supplyAsync(() -> {
try {
return webAgent.execute(map);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}).thenApply(parserFunction);
try {
result = cf.get();
} catch (Exception e) {
throw new RuntimeException(e);
}
return result;
}
/**
* restApi json格式自动获取所有分页
* @param map 运行参数
* @param pageIndexKey 页码key
* @param totalKey 总记录条数key
* @param pageSize
* @return
*/
public List<R> executePage(Map<String, Object> map, String pageIndexKey, String totalKey, Integer pageSize) {
List<R> list = Collections.synchronizedList(new ArrayList<>());
WebAgent data = webAgent.execute(map);
Complete the code above, taking into account the cross-file context provided. Your solution must work correctly with the related files in the project.
Place your complete solution in /app/solution.py