diff --git a/bocai.db b/bocai.db index 6186e3a..9b14ec1 100644 Binary files a/bocai.db and b/bocai.db differ diff --git a/pom.xml b/pom.xml index 9b6e291..b9804d0 100644 --- a/pom.xml +++ b/pom.xml @@ -92,11 +92,38 @@ + bocai org.springframework.boot spring-boot-maven-plugin + + net.roseboy + classfinal-maven-plugin + 1.2.1 + + + package + + classFinal + + + + + + # + + com.tem.bocai + + org.springframework.* + + + + false + + + \ No newline at end of file diff --git a/src/main/java/com/tem/bocai/schedules/CrawlerSchedule.java b/src/main/java/com/tem/bocai/schedules/CrawlerSchedule.java index bfe5d80..1a2da1a 100644 --- a/src/main/java/com/tem/bocai/schedules/CrawlerSchedule.java +++ b/src/main/java/com/tem/bocai/schedules/CrawlerSchedule.java @@ -6,6 +6,7 @@ import com.tem.bocai.util.*; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import us.codecraft.webmagic.Spider; @@ -23,6 +24,8 @@ public class CrawlerSchedule { private LoginInfoRepository loginInfoRepository; private static final int MAX_CRA = 3; private static final Integer ONOFF = 0; + @Value("${pypath}") + private String pypath; // 每天凌晨2点执行爬取开奖结果 //@Scheduled(cron = "0 0 2 * * ?") // 每7秒执行一次爬取开奖结果 @@ -55,7 +58,7 @@ public class CrawlerSchedule { System.out.println("使用token: " + (token.length() > 20 ? token.substring(0, 20) + "..." : token)); // 创建爬虫实例,传入token - LotteryWebMagicCrawler crawler = new LotteryWebMagicCrawler(token); + LotteryWebMagicCrawler crawler = new LotteryWebMagicCrawler(token,pypath); String todayDate = DateUtils.getTodayDate();// 4. 执行爬虫 String url = firstByOrderByCreateTimeDesc.getLoginUrl()+"/member/dresult?lottery=SGFT&date="+todayDate; diff --git a/src/main/java/com/tem/bocai/schedules/ExBetScriptSchedule.java b/src/main/java/com/tem/bocai/schedules/ExBetScriptSchedule.java index 768b5ac..d3948c1 100644 --- a/src/main/java/com/tem/bocai/schedules/ExBetScriptSchedule.java +++ b/src/main/java/com/tem/bocai/schedules/ExBetScriptSchedule.java @@ -3,6 +3,7 @@ package com.tem.bocai.schedules; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import org.json.JSONArray; +import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @@ -27,6 +28,9 @@ public class ExBetScriptSchedule { @Autowired private BetRecordRepository betRecordRepository; + + @Value("${pypath}") + private String pypath; /** * 处理文件路径,确保路径正确 @@ -107,7 +111,7 @@ public class ExBetScriptSchedule { // 创建ProcessBuilder并设置工作目录为PyModel ProcessBuilder pb = new ProcessBuilder(command); // 设置工作目录为PyModel - pb.directory(new java.io.File("PyModel")); + pb.directory(new java.io.File(pypath)); // 执行Python脚本 Process process = pb.start(); diff --git a/src/main/java/com/tem/bocai/service/impl/LoginServiceImpl.java b/src/main/java/com/tem/bocai/service/impl/LoginServiceImpl.java index 2963253..ab47f02 100644 --- a/src/main/java/com/tem/bocai/service/impl/LoginServiceImpl.java +++ b/src/main/java/com/tem/bocai/service/impl/LoginServiceImpl.java @@ -9,6 +9,7 @@ import com.tem.bocai.util.*; import jakarta.transaction.Transactional; import lombok.val; import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import net.sourceforge.tess4j.Tesseract; import org.apache.http.client.methods.*; @@ -32,6 +33,9 @@ public class LoginServiceImpl implements LoginService { private LoginInfoRepository loginInfoRepository; private static final int MAX_CRA = 3; private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + @Value("${pypath}") + private String pypath; + @Override public String loginAutomatic(LoginInfoParam loginInfoParam) { @@ -45,7 +49,7 @@ public class LoginServiceImpl implements LoginService { //保存用户信息 addLoginInfo(loginInfoParam); // 2. 创建爬虫实例,传入token - LotteryWebMagicCrawler crawler = new LotteryWebMagicCrawler(token); + LotteryWebMagicCrawler crawler = new LotteryWebMagicCrawler(token,pypath); // 3. 创建数据处理器 LotteryDataPipeline pipeline = new LotteryDataPipeline(); diff --git a/src/main/java/com/tem/bocai/util/LotteryWebMagicCrawler.java b/src/main/java/com/tem/bocai/util/LotteryWebMagicCrawler.java index c31e0d5..adb361f 100644 --- a/src/main/java/com/tem/bocai/util/LotteryWebMagicCrawler.java +++ b/src/main/java/com/tem/bocai/util/LotteryWebMagicCrawler.java @@ -34,8 +34,11 @@ public class LotteryWebMagicCrawler implements PageProcessor { // 添加一个字段标记是否成功解析数据 private static volatile boolean lastParseSuccess = true; - public LotteryWebMagicCrawler(String token) { + private String path; + + public LotteryWebMagicCrawler(String token,String path) { this.token = token; + this.path =path; initSite(); } @@ -289,7 +292,7 @@ public class LotteryWebMagicCrawler implements PageProcessor { String url = "https://4701268539-esh.qdk63ayw8g.com/member/dresult?lottery=SGFT&date=2026-01-18"; // 创建爬虫 - Spider.create(new LotteryWebMagicCrawler("")) + Spider.create(new LotteryWebMagicCrawler("","")) .addUrl(url) // 添加起始URL .thread(1) // 线程数 .run(); // 开始爬取 diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f41e893..43c9b10 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -8,4 +8,6 @@ spring.datasource.password= spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true spring.jpa.database-platform=org.hibernate.community.dialect.SQLiteDialect -spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true \ No newline at end of file +spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true + +pypath:d:/py/PyModel \ No newline at end of file