调整逻辑
This commit is contained in:
@@ -12,8 +12,8 @@ public class TessConfig {
|
||||
|
||||
Tesseract instance = new Tesseract();
|
||||
instance.setLanguage("oci"); // 设置语言包,这里使用英语
|
||||
instance.setDatapath("src/main/resources/tessdata"); // 设置语言包路径
|
||||
// instance.setDatapath("tessdata"); // 设置语言包路径
|
||||
// instance.setDatapath("src/main/resources/tessdata"); // 设置语言包路径
|
||||
instance.setDatapath("tessdata"); // 设置语言包路径
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ public class CrawlerSchedule {
|
||||
}
|
||||
|
||||
|
||||
// @Scheduled(cron = "55 0/5 * * * ?")
|
||||
@Scheduled(cron = "55 0/5 * * * ?")
|
||||
//@Scheduled(cron = "*/9 * * * * ?")
|
||||
public void executePksHistory() {
|
||||
log.info("开始获取历史开奖结果");
|
||||
|
||||
@@ -26,7 +26,9 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.tem.bocai.entity.BetRecord;
|
||||
import com.tem.bocai.entity.LotteryResult;
|
||||
import com.tem.bocai.repository.BetRecordRepository;
|
||||
import com.tem.bocai.repository.LotteryResultRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
@@ -39,6 +41,9 @@ public class ExBetScriptSchedule {
|
||||
@Autowired
|
||||
private BetRecordRepository betRecordRepository;
|
||||
|
||||
@Autowired
|
||||
private LotteryResultRepository lotteryResultRepository;
|
||||
|
||||
@Value("${pypath}")
|
||||
private String pypath;
|
||||
|
||||
@@ -67,8 +72,8 @@ public class ExBetScriptSchedule {
|
||||
|
||||
log.info("开始执行Python脚本...");
|
||||
|
||||
// 获取当前时间,格式化为yyyy-MM-dd HH:mm:ss
|
||||
String currentTime = java.time.LocalDateTime.now().format(
|
||||
// 获取当前时间减去5分钟,格式化为yyyy-MM-dd HH:mm:ss
|
||||
String currentTime = java.time.LocalDateTime.now().plusMinutes(5).format(
|
||||
java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
||||
);
|
||||
|
||||
@@ -309,57 +314,44 @@ public class ExBetScriptSchedule {
|
||||
|
||||
|
||||
/**
|
||||
* 检查PyModel/current_data目录下最新的文件是否存在新数据
|
||||
* 检查数据库中最新的开奖记录是否存在新数据
|
||||
* @return 如果存在新数据返回true,否则返回false
|
||||
*/
|
||||
private boolean checkNewDataExists() {
|
||||
try {
|
||||
File currentDataDir = new File(pypath, "current_data");
|
||||
if (!currentDataDir.exists() || !currentDataDir.isDirectory()) {
|
||||
log.info("current_data目录不存在");
|
||||
// 查询最新的开奖记录
|
||||
Optional<LotteryResult> latestResult = lotteryResultRepository.findTopByOrderByTimeDesc();
|
||||
if (!latestResult.isPresent()) {
|
||||
log.info("数据库中未找到开奖记录");
|
||||
return false;
|
||||
}
|
||||
|
||||
File[] files = currentDataDir.listFiles();
|
||||
if (files == null || files.length == 0) {
|
||||
log.info("current_data目录为空");
|
||||
// 获取最新记录的时间
|
||||
String timeStr = latestResult.get().getTime();
|
||||
if (timeStr == null || timeStr.isEmpty()) {
|
||||
log.info("最新开奖记录时间为空");
|
||||
return false;
|
||||
}
|
||||
|
||||
File latestFile = null;
|
||||
FileTime latestTime = null;
|
||||
|
||||
for (File file : files) {
|
||||
if (file.getName().endsWith(".json")) {
|
||||
Path path = Paths.get(file.getAbsolutePath());
|
||||
BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class);
|
||||
FileTime fileTime = attrs.lastModifiedTime();
|
||||
|
||||
if (latestTime == null || fileTime.compareTo(latestTime) > 0) {
|
||||
latestTime = fileTime;
|
||||
latestFile = file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (latestFile == null) {
|
||||
log.info("未找到JSON文件");
|
||||
// 解析时间字符串为LocalDateTime
|
||||
LocalDateTime recordTime;
|
||||
try {
|
||||
// 假设时间格式为yyyy-MM-dd HH:mm:ss
|
||||
recordTime = LocalDateTime.parse(timeStr, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
} catch (Exception e) {
|
||||
log.error("解析开奖记录时间失败: {}", timeStr, e);
|
||||
return false;
|
||||
}
|
||||
|
||||
LocalDateTime fileModifiedTime = LocalDateTime.ofInstant(
|
||||
latestTime.toInstant(),
|
||||
ZoneId.systemDefault()
|
||||
);
|
||||
|
||||
// 检查时间是否在最近5分钟内
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
LocalDateTime fiveMinutesAgo = now.minusMinutes(5);
|
||||
|
||||
if (fileModifiedTime.isAfter(fiveMinutesAgo)) {
|
||||
log.info("发现新数据文件: {}, 修改时间: {}", latestFile.getName(), fileModifiedTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
if (recordTime.isAfter(fiveMinutesAgo)) {
|
||||
log.info("发现新开奖记录: 期号={}, 时间={}", latestResult.get().getIssue(), timeStr);
|
||||
return true;
|
||||
} else {
|
||||
log.info("最新数据文件: {}, 修改时间: {}, 超过5分钟,跳过执行", latestFile.getName(), fileModifiedTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
log.info("最新开奖记录: 期号={}, 时间={}, 超过5分钟,跳过执行", latestResult.get().getIssue(), timeStr);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,8 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
|
||||
*
|
||||
* @return 当天日期的字符串,例如:2026-01-27
|
||||
*/
|
||||
|
||||
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
public static String getTodayDate() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
LocalTime thresholdTime = LocalTime.of(6, 1, 0);
|
||||
@@ -60,8 +62,14 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
|
||||
return date.format(DateTimeFormatter.ofPattern(YYYY_MM_DD));
|
||||
}
|
||||
/*public static String getTodayDate() {
|
||||
LocalDate today = LocalDate.now();
|
||||
return today.format(DateTimeFormatter.ofPattern(YYYY_MM_DD));
|
||||
// Java 17中可使用var简化局部变量声明
|
||||
var now = LocalDateTime.now();
|
||||
// 核心判断逻辑:小时数<6则取前一天,否则取当天
|
||||
LocalDate targetDate = now.getHour() <= 6
|
||||
? now.toLocalDate().minusDays(1)
|
||||
: now.toLocalDate();
|
||||
// 格式化返回
|
||||
return targetDate.format(DATE_FORMATTER);
|
||||
}*/
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -35,9 +35,10 @@ public class HttpClientExample {
|
||||
String url = "https://api.api168168.com/pks/getPksHistoryList.do?lotCode=10058&"+todayDate;
|
||||
|
||||
// 设置代理 127.0.0.1:7890
|
||||
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 7890));
|
||||
// Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 7890));
|
||||
|
||||
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(proxy);
|
||||
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
|
||||
// HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(proxy);
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setRequestProperty("Origin", "https://xy678kjw.com");
|
||||
conn.setRequestProperty("Referer", "https://xy678kjw.com/");
|
||||
|
||||
@@ -290,7 +290,7 @@ public class LotteryWebMagicCrawler implements PageProcessor {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
String url = "https://4701268539-esh.qdk63ayw8g.com/member/dresult?lottery=SGFT&date=2026-01-18";
|
||||
String url = "https://4701268539-esh.qdk63ayw8g.com/member/dresult?lottery=SGFT&date=2026-02-06";
|
||||
|
||||
// 创建爬虫
|
||||
Spider.create(new LotteryWebMagicCrawler("",""))
|
||||
|
||||
@@ -373,16 +373,16 @@ public class TokenCacheService {
|
||||
// 等待一下再发送登录请求
|
||||
Thread.sleep(1500 + (long) (Math.random() * 1000));
|
||||
|
||||
// 新增代码:增加代理
|
||||
String proxyHost = "127.0.0.1";
|
||||
int proxyPort = 7890;
|
||||
HttpHost proxy = new HttpHost(proxyHost, proxyPort);
|
||||
RequestConfig proxyConfig = RequestConfig.custom()
|
||||
.setProxy(proxy)
|
||||
.build();
|
||||
// // 新增代码:增加代理
|
||||
// String proxyHost = "127.0.0.1";
|
||||
// int proxyPort = 7890;
|
||||
// HttpHost proxy = new HttpHost(proxyHost, proxyPort);
|
||||
// RequestConfig proxyConfig = RequestConfig.custom()
|
||||
// .setProxy(proxy)
|
||||
// .build();
|
||||
HttpPost loginPost = createLoginRequest(code,loginInfoParam);
|
||||
// 新增代码:将代理类放入配置中
|
||||
loginPost.setConfig(proxyConfig);
|
||||
// // 新增代码:将代理类放入配置中
|
||||
// loginPost.setConfig(proxyConfig);
|
||||
try (CloseableHttpResponse loginResponse = httpClient.execute(loginPost)) {
|
||||
return processLoginResponse(loginResponse, cookieStore);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user