Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
Achilles
2024-01-11 09:38:46 +08:00
7 changed files with 94 additions and 14 deletions

View File

@@ -272,8 +272,9 @@ public class StockService {
return result; return result;
} }
public String getNewsInfo(String url) { public List<String> getNewsInfo(String url) {
String result = ""; String result = "";
List<String> list = new ArrayList<>();
try { try {
// 使用Jsoup连接到网页 // 使用Jsoup连接到网页
Document doc = Jsoup.connect(url) Document doc = Jsoup.connect(url)
@@ -281,11 +282,14 @@ public class StockService {
.header("Referer", "https://www.business-standard.com/") .header("Referer", "https://www.business-standard.com/")
.header("Accept-Language", "en-US,en;q=0.9") .header("Accept-Language", "en-US,en;q=0.9")
.get(); .get();
result = doc.html().substring(doc.html().indexOf("articleBody") + 15, doc.html().indexOf(",\"author\":") - 1); result = doc.html().substring(doc.html().indexOf("articleBody") + 14, doc.html().indexOf(",\"author\":") - 1);
list.add(result);
list.add(doc.html().substring(doc.html().indexOf("og:title") + 19, doc.html().indexOf("<meta property=\"og:url") - 5));
} catch (Exception e) { } catch (Exception e) {
return e.toString(); list.add(e.toString());
return list;
} }
return result; return list;
} }
public ServerResponse getStock(int pageNum, int pageSize, String keyWords, String stockPlate, String stockType, public ServerResponse getStock(int pageNum, int pageSize, String keyWords, String stockPlate, String stockType,
@@ -941,8 +945,10 @@ public class StockService {
market.setName("BSESENSEX指数"); market.setName("BSESENSEX指数");
vo1.setIndexVo(market); vo1.setIndexVo(market);
String type = "min"; String period = "P1D";
List<JSONObject> list = InvestingApis.of().kline(StockCode.of(stockCode), type); String interval = "PT5M";
String type = "day";
List<JSONObject> list = InvestingApis.of().kIndex(stockCode,period,interval, type);
if(list == null || list.size() == 0){ if(list == null || list.size() == 0){
type = "day"; type = "day";
list = InvestingApis.of().kline(StockCode.of(stockCode), type); list = InvestingApis.of().kline(StockCode.of(stockCode), type);
@@ -954,13 +960,15 @@ public class StockService {
} }
try { try {
IndiaIndexVo vo2 = new IndiaIndexVo(); IndiaIndexVo vo2 = new IndiaIndexVo();
String stockCode = "8985"; //"17940"; String stockCode = "17940"; //"17940";8985
IndiaStockVO market = InvestingApis.of().market(StockCode.of(stockCode)); IndiaStockVO market = InvestingApis.of().market(StockCode.of(stockCode));
market.setName("NIFTY50指数"); market.setName("NIFTY50指数");
vo2.setIndexVo(market); vo2.setIndexVo(market);
String type = "min"; String period = "P1D";
List<JSONObject> list = InvestingApis.of().kline(StockCode.of(stockCode), type); String interval = "PT1M";
String type = "day";
List<JSONObject> list = InvestingApis.of().kIndex(stockCode,period,interval, type);
if(list == null || list.size() == 0){ if(list == null || list.size() == 0){
type = "day"; type = "day";
list = InvestingApis.of().kline(StockCode.of(stockCode), type); list = InvestingApis.of().kline(StockCode.of(stockCode), type);

View File

@@ -153,7 +153,6 @@ public class InvestingApis {
"Time": "1698055197", "Time": "1698055197",
"Url": "/equities/aditya-birla", "Url": "/equities/aditya-birla",
"Volume": 3693615 "Volume": 3693615
* @param httpClient
* @param currPage * @param currPage
* @param pageSize * @param pageSize
* @return * @return
@@ -252,7 +251,35 @@ public class InvestingApis {
.collect(Collectors.toList()) .collect(Collectors.toList())
; ;
} }
public List<JSONObject> kIndex(String code,String period, String interval,String type) throws IOException {
if(code == null) {
throw new RuntimeException("找不到股票信息");
}
Date nowDate = new Date();
JSONObject json = InvestingInvokerApis.of().__IndiaIndex(code, period,interval);
return json
.getJSONArray("data")
.stream()
.map(val -> {
JSONArray _ar = (JSONArray) val;
JSONObject item = new JSONObject();
item.put("date", _ar.get(0));
item.put("open", _ar.get(1));
item.put("high", _ar.get(2));
item.put("low", _ar.get(3));
item.put("close", _ar.get(4));
item.put("volume", _ar.get(5));
return item;
}).filter(val -> {
if("day".equalsIgnoreCase(type)) {
return DateUtil.isSameDay(nowDate, new Date(val.getLong("date")));
}
return true;
})
.collect(Collectors.toList())
;
}
public static InvestingApis of() { public static InvestingApis of() {
return new InvestingApis(); return new InvestingApis();
} }

View File

@@ -201,6 +201,15 @@ public class InvestingInvokerApis {
String body = httpClient().newCall(builder.build()).execute().body().string(); String body = httpClient().newCall(builder.build()).execute().body().string();
return JSON.parseObject(body); return JSON.parseObject(body);
} }
public JSONObject __IndiaIndex(String code,String period, String interval)throws IOException {
String tmpl = "https://api.investing.com/api/financialdata/{}/historical/chart/?period={}&interval={}&pointscount=160";
String url = StrFormatter.format(tmpl, code, period, interval);
Builder builder = builderGet(url);
String body = httpClient().newCall(builder.build()).execute().body().string();
return JSON.parseObject(body);
}
public static InvestingInvokerApis of() { public static InvestingInvokerApis of() {
return new InvestingInvokerApis(); return new InvestingInvokerApis();

View File

@@ -71,4 +71,10 @@ public class BtodayStockPO {
/** /**
* 上次更新时间 */ * 上次更新时间 */
Date lastUpdateTime; Date lastUpdateTime;
/** 是否锁定 0否 1是 */
Integer isLock;
/** 是否展示 0是 1否 */
Integer isShow;
} }

View File

@@ -117,15 +117,15 @@ public class InvestingTask {
String id = contentUrl.substring(contentUrl.lastIndexOf("-") + 1, contentUrl.lastIndexOf("_")); String id = contentUrl.substring(contentUrl.lastIndexOf("-") + 1, contentUrl.lastIndexOf("_"));
String imgUrl = n.substring(n.indexOf("img src=") + 9, n.indexOf("?")); String imgUrl = n.substring(n.indexOf("img src=") + 9, n.indexOf("?"));
String time = n.substring(n.indexOf("Last Updated") + 23, n.indexOf("IST") - 9); String time = n.substring(n.indexOf("Last Updated") + 23, n.indexOf("IST") - 9);
String title = n.substring(n.indexOf("html\">") + 6, n.indexOf("<div class=\"short-video-img\">") - 47);
SiteNews siteNews = new SiteNews(); SiteNews siteNews = new SiteNews();
siteNews.setAddTime(new Date()); siteNews.setAddTime(new Date());
siteNews.setSourceId(id); siteNews.setSourceId(id);
siteNews.setTitle(title);
siteNews.setDescription(time); siteNews.setDescription(time);
siteNews.setImgurl(imgUrl); siteNews.setImgurl(imgUrl);
siteNews.setContent(stockService.getNewsInfo(contentUrl)); List<String> newsInfo = stockService.getNewsInfo(contentUrl);
siteNews.setContent(newsInfo.get(0));
siteNews.setTitle(newsInfo.get(1));
List<SiteNews> list = newsRepository.findAll(QSiteNewsPO.siteNewsPO.sourceId.eq(id)); List<SiteNews> list = newsRepository.findAll(QSiteNewsPO.siteNewsPO.sourceId.eq(id));
if (list.size() == 0) { if (list.size() == 0) {
newsRepository.save(siteNews); newsRepository.save(siteNews);

View File

@@ -261,6 +261,8 @@ public class Scraper {
btodayStock.setSelfUrl(url); btodayStock.setSelfUrl(url);
btodayStock.setUrl(detailUrl); btodayStock.setUrl(detailUrl);
btodayStock.setLastUpdateTime(new Date()); btodayStock.setLastUpdateTime(new Date());
btodayStock.setIsLock(0);
btodayStock.setIsShow(0);
btodayStockRepo.save(btodayStock); btodayStockRepo.save(btodayStock);
/* if (webInfo != null) { /* if (webInfo != null) {

View File

@@ -167,6 +167,34 @@ public class StockApiController {
return ServerResponse.createBySuccess(newsRepository.findAll(ConditionBuilder.builder().build(), PageParam.of(pageNum, pageSize), QSiteNewsPO.siteNewsPO.id.desc())); return ServerResponse.createBySuccess(newsRepository.findAll(ConditionBuilder.builder().build(), PageParam.of(pageNum, pageSize), QSiteNewsPO.siteNewsPO.id.desc()));
} }
@RequestMapping({"test.do"})
@ResponseBody
public ServerResponse test(@RequestParam("url") String url, @RequestParam("pageNum") Integer pageNum) {
String news = stockService.getNews();
List<String> newsList = Arrays.asList(news.split("<a href="));
newsList = newsList.subList(1, newsList.size());
newsList.forEach( n -> {
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 src=") + 9, n.indexOf("?"));
String time = n.substring(n.indexOf("Last Updated") + 23, n.indexOf("IST") - 9);
SiteNews siteNews = new SiteNews();
siteNews.setAddTime(new Date());
siteNews.setSourceId(id);
siteNews.setDescription(time);
siteNews.setImgurl(imgUrl);
List<String> newsInfo = stockService.getNewsInfo(contentUrl);
siteNews.setContent(newsInfo.get(0));
siteNews.setTitle(newsInfo.get(1));
List<SiteNews> list = newsRepository.findAll(QSiteNewsPO.siteNewsPO.sourceId.eq(id));
if (list.size() == 0) {
newsRepository.save(siteNews);
}
});
return ServerResponse.createBySuccess();
}
//印度股票时线-K线 //印度股票时线-K线
@RequestMapping({"getINDTimeK.do"}) @RequestMapping({"getINDTimeK.do"})
@ApiOperation(value = "印度股票K线", httpMethod = "GET") @ApiOperation(value = "印度股票K线", httpMethod = "GET")