From a403cba96456f9080a5acb738b8c69dbf512d84e Mon Sep 17 00:00:00 2001 From: Weng JinPeng Date: Mon, 8 Jul 2024 12:38:13 +0800 Subject: [PATCH 1/5] =?UTF-8?q?fix:=20=E6=97=B6=E9=97=B4=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E9=94=99=E4=B9=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/stock/market/domain/basic/service/StockService.java | 2 +- .../java/cn/stock/market/infrastructure/job/InvestingTask.java | 2 +- src/main/java/cn/stock/market/web/StockApiController.java | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/cn/stock/market/domain/basic/service/StockService.java b/src/main/java/cn/stock/market/domain/basic/service/StockService.java index 954bc32..e6f3b69 100644 --- a/src/main/java/cn/stock/market/domain/basic/service/StockService.java +++ b/src/main/java/cn/stock/market/domain/basic/service/StockService.java @@ -255,7 +255,7 @@ public class StockService { .header("Accept-Language", "en-US,en;q=0.9") .get(); // result = doc.html().substring(doc.html().indexOf("
"),doc.html().lastIndexOf("
")+500); - Elements divElements = doc.select("div.listingstyle_cardlistlist__Cr4Ym"); + Elements divElements = doc.select("div.listingstyle_cardlistlist__dfq57"); StringBuilder sb = new StringBuilder(); for (Element divElement : divElements) { sb.append(divElement.outerHtml()).append("\n"); diff --git a/src/main/java/cn/stock/market/infrastructure/job/InvestingTask.java b/src/main/java/cn/stock/market/infrastructure/job/InvestingTask.java index 5e0752d..1b761fb 100644 --- a/src/main/java/cn/stock/market/infrastructure/job/InvestingTask.java +++ b/src/main/java/cn/stock/market/infrastructure/job/InvestingTask.java @@ -123,7 +123,7 @@ public class InvestingTask { String imgUrl = n.substring(n.indexOf("img loading=\"lazy\" src=") + 24, n.indexOf("?")); // String time = n.substring(n.indexOf("Last Updated") + 23, n.indexOf("IST") - 9); // Extract the date and time using regex - Pattern pattern = Pattern.compile("Updated On : (.*?)"); + Pattern pattern = Pattern.compile("Updated On : (.*?)"); Matcher matcher = pattern.matcher(n); String time = ""; if (matcher.find()) { diff --git a/src/main/java/cn/stock/market/web/StockApiController.java b/src/main/java/cn/stock/market/web/StockApiController.java index a65e504..2b2d88c 100644 --- a/src/main/java/cn/stock/market/web/StockApiController.java +++ b/src/main/java/cn/stock/market/web/StockApiController.java @@ -179,8 +179,9 @@ public class StockApiController { String contentUrl = n.substring(1, n.indexOf("class=\"img-smllnews\"") - 2); String id = contentUrl.substring(contentUrl.lastIndexOf("-") + 1, contentUrl.lastIndexOf("_")); String imgUrl = n.substring(n.indexOf("img loading=\"lazy\" src=") + 24, n.indexOf("?")); +// String time = n.substring(n.indexOf("Last Updated") + 23, n.indexOf("IST") - 9); // Extract the date and time using regex - Pattern pattern = Pattern.compile("Updated On : (.*?)"); + Pattern pattern = Pattern.compile("Updated On : (.*?)"); Matcher matcher = pattern.matcher(n); String time = ""; if (matcher.find()) { From 2f9e54bf4fddc1c20f6f4487b2e136cdbfcca0ed Mon Sep 17 00:00:00 2001 From: gavin Date: Fri, 12 Jul 2024 15:33:25 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E8=BF=9E=E6=8E=A5=20=E6=9B=B4=E6=96=B0=E6=96=B0?= =?UTF-8?q?=E9=97=BB=E6=97=B6=E9=97=B4=E6=A0=BC=E5=BC=8F=E4=B8=BA24?= =?UTF-8?q?=E5=B0=8F=E6=97=B6=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infrastructure/job/InvestingTask.java | 3 ++- .../cn/stock/market/utils/DateTimeUtil.java | 21 +++++++++++++++++++ src/main/resources/application-base-alpha.yml | 10 ++++----- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/main/java/cn/stock/market/infrastructure/job/InvestingTask.java b/src/main/java/cn/stock/market/infrastructure/job/InvestingTask.java index 1b761fb..e93d0da 100644 --- a/src/main/java/cn/stock/market/infrastructure/job/InvestingTask.java +++ b/src/main/java/cn/stock/market/infrastructure/job/InvestingTask.java @@ -7,6 +7,7 @@ import cn.stock.market.domain.basic.repository.StockRepository; import cn.stock.market.domain.basic.service.StockService; import cn.stock.market.infrastructure.api.investing.InvestingInvokerApis; import cn.stock.market.infrastructure.db.po.QSiteNewsPO; +import cn.stock.market.utils.DateTimeUtil; import cn.stock.market.utils.Utils; import com.ag.utils.CollectionUtils; import com.alibaba.fastjson.JSON; @@ -127,7 +128,7 @@ public class InvestingTask { Matcher matcher = pattern.matcher(n); String time = ""; if (matcher.find()) { - time = matcher.group(1).trim(); + time = DateTimeUtil.formatDateTimeFor24H(matcher.group(1).trim(),"dd MMM yyyy | hh:mm a"); } SiteNews siteNews = new SiteNews(); diff --git a/src/main/java/cn/stock/market/utils/DateTimeUtil.java b/src/main/java/cn/stock/market/utils/DateTimeUtil.java index 914ecf1..66e33d2 100644 --- a/src/main/java/cn/stock/market/utils/DateTimeUtil.java +++ b/src/main/java/cn/stock/market/utils/DateTimeUtil.java @@ -5,6 +5,8 @@ import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; +import java.util.Locale; + import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; @@ -186,6 +188,25 @@ public class DateTimeUtil { } + public static String formatDateTimeFor24H(String inputDateTime,String inputFormatStr){ + String outputDateTime = ""; + // 1. 解析日期时间 + SimpleDateFormat inputFormat = new SimpleDateFormat(inputFormatStr, Locale.ENGLISH); + Date date = null; + try { + date = inputFormat.parse(inputDateTime); + } catch (Exception e) { + e.printStackTrace(); + } + + if (date != null) { + // 2. 转换为24小时制 + SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + outputDateTime = outputFormat.format(date); + } + return outputDateTime; + } + public static void main(String[] args) { parseToDateByMinute(10); } diff --git a/src/main/resources/application-base-alpha.yml b/src/main/resources/application-base-alpha.yml index fb4cc6d..6572790 100644 --- a/src/main/resources/application-base-alpha.yml +++ b/src/main/resources/application-base-alpha.yml @@ -3,9 +3,9 @@ spring: show-sql: true # Redis配置 redis: - host: 43.132.212.180 - password: ruTZ9J3gaDhknJ - port: 36379 + host: lb-b6sze686-7db6hgvsx05ef8nz.clb.sg-tencentclb.net + password: a5v8b86P4mVzFlUqJV + port: 56379 database: 1 lettuce: pool: @@ -17,9 +17,9 @@ spring: datasource: stock-market: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://149.88.86.7:33306/india_stock?useUnicode=true&characterEncoding=utf-8 + url: jdbc:mysql://lb-1ju43bvw-p0ecnv4by9ju8six.clb.ap-singapore.tencentclb.com:53306/india_stock?useUnicode=true&characterEncoding=utf-8 username: root - password: 33BsUUcnXRYgwtIND + password: uNejHIFQGJOUtYTmE maxActive: 500 testWhileIdle: true validationQuery: SELECT 1 From b321fd9d4efb8499c4ddbfbced37d8341b20489f Mon Sep 17 00:00:00 2001 From: Thanh Nguyen Date: Tue, 23 Jul 2024 09:39:48 +0700 Subject: [PATCH 3/5] Update automatic-deployment link --- .gitlab-ci.yml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7258c6b..5119c46 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,7 +2,7 @@ stages: # 构建 - build - dockerize - - webhook + - deploy build: image: maven:3.6.3-openjdk-8 @@ -60,16 +60,20 @@ dockerize: - docker push juyoutech/india_stock_market:latest - docker push juyoutech/india_stock_market:$CI_PIPELINE_ID - docker push juyoutech/india_stock_market:$CI_COMMIT_BRANCH -webhook: - stage: webhook +deploy-dev: + stage: deploy only: - develop script: - - echo ">>>>>>Start Deploy<<<<<<" + - echo "Deploying application..." - ls - apt-get update - apt-get install -y curl - - curl --max-time 30 http://149.88.86.7:11113/api/webhook/justpull?project=india_market_java\&setenv_file=alpha.sh\&publish_env=alpha\&shell=deploy-test.sh - - echo ">>>>>>Start Deploy Finish<<<<<<" + - | + curl -X POST \ + -H "Content-Type: application/json" \ + -d '{"namespace":"yddev", "deployment_name":"india-stock-market"}' \ + https://updater-yddev.moneytj.com/restart-deployment + - echo "Application successfully deployed." From 2e4449bd64b1e56acb0d760339da61d92041660a Mon Sep 17 00:00:00 2001 From: gavin Date: Fri, 26 Jul 2024 14:53:50 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=A4=A7=E7=9B=98=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=9B=B4=E6=8D=A2moneycontrol=20=E6=95=B0=E6=8D=AE=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/basic/service/StockService.java | 28 +++++++++---------- .../market/infrastructure/api/TodayApis.java | 9 +++--- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/main/java/cn/stock/market/domain/basic/service/StockService.java b/src/main/java/cn/stock/market/domain/basic/service/StockService.java index e6f3b69..78f277f 100644 --- a/src/main/java/cn/stock/market/domain/basic/service/StockService.java +++ b/src/main/java/cn/stock/market/domain/basic/service/StockService.java @@ -982,7 +982,7 @@ public class StockService { String exchange = "bse"; IndiaIndexVo vo1 = new IndiaIndexVo(); String coCode = "20558"; - JSONObject object = TodayApis.getStockDetail(exchange, coCode); + JSONObject object = TodayApis.getStockDetail("in%3BSEN", coCode); IndiaStockVO market = objToVo(object); market.setName("BSESENSEX指数"); vo1.setIndexVo(market); @@ -1012,7 +1012,7 @@ public class StockService { String exchange = "nse"; IndiaIndexVo vo1 = new IndiaIndexVo(); String coCode = "20559"; - JSONObject object = TodayApis.getStockDetail(exchange, coCode); + JSONObject object = TodayApis.getStockDetail("in%3BNSX", coCode); IndiaStockVO market = objToVo(object); market.setName("NIFTY50指数"); vo1.setIndexVo(market); @@ -1042,23 +1042,23 @@ public class StockService { } private IndiaStockVO objToVo(JSONObject object){ IndiaStockVO market = new IndiaStockVO(); - if(object.containsKey("prev_close")){ - market.setClose(object.getString("prev_close")); + if(object.containsKey("priceprevclose")){ + market.setClose(object.getString("priceprevclose")); } - if(object.containsKey("price")){ - market.setNowPrice(object.getString("price")); + if(object.containsKey("pricecurrent")){ + market.setNowPrice(object.getString("pricecurrent")); } - if(object.containsKey("perchg")){ - market.setRate(object.getString("perchg")); + if(object.containsKey("pricepercentchange")){ + market.setRate(object.getString("pricepercentchange")); } - if(object.containsKey("high_price")){ - market.setHigh(object.getString("high_price")); + if(object.containsKey("HIGH")){ + market.setHigh(object.getString("HIGH")); } - if(object.containsKey("low_price")){ - market.setLow(object.getString("low_price")); + if(object.containsKey("LOW")){ + market.setLow(object.getString("LOW")); } - if(object.containsKey("open_price")){ - market.setOpen(object.getString("open_price")); + if(object.containsKey("OPEN")){ + market.setOpen(object.getString("OPEN")); } return market; // stockListVO.setName(jsonObject.getString("companyname")); diff --git a/src/main/java/cn/stock/market/infrastructure/api/TodayApis.java b/src/main/java/cn/stock/market/infrastructure/api/TodayApis.java index ca004ab..b41b256 100644 --- a/src/main/java/cn/stock/market/infrastructure/api/TodayApis.java +++ b/src/main/java/cn/stock/market/infrastructure/api/TodayApis.java @@ -187,18 +187,17 @@ public class TodayApis { //获取详情 public static JSONObject getStockDetail(String exchange,String coCode){ - String url = String.format("https://marketapi.intoday.in/widget/stockdetail/pullview?co_code=%s&exchange=%s",coCode,exchange); + String url = String.format("https://priceapi.moneycontrol.com/pricefeed/notapplicable/inidicesindia/%s",exchange); String str = get(url); JSONObject object = JSON.parseObject(str); boolean bool = false; - if(object.containsKey("success")){ - bool = object.getBoolean("success"); + if(object.containsKey("code")){ + bool = object.getInteger("code") == 200; } if(!bool){ return new JSONObject(); } - JSONArray jsonArray = JSON.parseArray(object.getString("data")); - JSONObject entity = JSON.parseObject(jsonArray.get(0).toString()); + JSONObject entity = JSON.parseObject(object.getString("data")); return entity; } From 5b2eb8519af233ef8d342975b62480aa5448b49b Mon Sep 17 00:00:00 2001 From: gavin Date: Fri, 26 Jul 2024 15:04:56 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E5=A4=A7=E7=9B=98=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=94=B9=E4=B8=BA6=E7=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/cn/stock/market/web/StockApiController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/cn/stock/market/web/StockApiController.java b/src/main/java/cn/stock/market/web/StockApiController.java index 2b2d88c..103dec2 100644 --- a/src/main/java/cn/stock/market/web/StockApiController.java +++ b/src/main/java/cn/stock/market/web/StockApiController.java @@ -247,7 +247,7 @@ public class StockApiController { @ResponseBody public ServerResponse getIndiaIndexByToday() { String INDEX_CODE = "TODAY_INDEX"; - return RequestCacheUtils.cache("getIndiaIndexByToday.do", INDEX_CODE,60000, (string) -> { + return RequestCacheUtils.cache("getIndiaIndexByToday.do", INDEX_CODE,6000, (string) -> { return this.stockService.getIndexByBtoday(); }); }