Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
@@ -272,8 +272,9 @@ public class StockService {
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getNewsInfo(String url) {
|
||||
public List<String> getNewsInfo(String url) {
|
||||
String result = "";
|
||||
List<String> list = new ArrayList<>();
|
||||
try {
|
||||
// 使用Jsoup连接到网页
|
||||
Document doc = Jsoup.connect(url)
|
||||
@@ -281,11 +282,14 @@ public class StockService {
|
||||
.header("Referer", "https://www.business-standard.com/")
|
||||
.header("Accept-Language", "en-US,en;q=0.9")
|
||||
.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) {
|
||||
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,
|
||||
@@ -941,8 +945,10 @@ public class StockService {
|
||||
market.setName("BSESENSEX指数");
|
||||
vo1.setIndexVo(market);
|
||||
|
||||
String type = "min";
|
||||
List<JSONObject> list = InvestingApis.of().kline(StockCode.of(stockCode), type);
|
||||
String period = "P1D";
|
||||
String interval = "PT5M";
|
||||
String type = "day";
|
||||
List<JSONObject> list = InvestingApis.of().kIndex(stockCode,period,interval, type);
|
||||
if(list == null || list.size() == 0){
|
||||
type = "day";
|
||||
list = InvestingApis.of().kline(StockCode.of(stockCode), type);
|
||||
@@ -954,13 +960,15 @@ public class StockService {
|
||||
}
|
||||
try {
|
||||
IndiaIndexVo vo2 = new IndiaIndexVo();
|
||||
String stockCode = "8985"; //"17940";
|
||||
String stockCode = "17940"; //"17940";8985
|
||||
IndiaStockVO market = InvestingApis.of().market(StockCode.of(stockCode));
|
||||
market.setName("NIFTY50指数");
|
||||
vo2.setIndexVo(market);
|
||||
|
||||
String type = "min";
|
||||
List<JSONObject> list = InvestingApis.of().kline(StockCode.of(stockCode), type);
|
||||
String period = "P1D";
|
||||
String interval = "PT1M";
|
||||
String type = "day";
|
||||
List<JSONObject> list = InvestingApis.of().kIndex(stockCode,period,interval, type);
|
||||
if(list == null || list.size() == 0){
|
||||
type = "day";
|
||||
list = InvestingApis.of().kline(StockCode.of(stockCode), type);
|
||||
|
||||
@@ -153,7 +153,6 @@ public class InvestingApis {
|
||||
"Time": "1698055197",
|
||||
"Url": "/equities/aditya-birla",
|
||||
"Volume": 3693615
|
||||
* @param httpClient
|
||||
* @param currPage
|
||||
* @param pageSize
|
||||
* @return
|
||||
@@ -252,6 +251,34 @@ public class InvestingApis {
|
||||
.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() {
|
||||
return new InvestingApis();
|
||||
|
||||
@@ -202,6 +202,15 @@ public class InvestingInvokerApis {
|
||||
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() {
|
||||
return new InvestingInvokerApis();
|
||||
}
|
||||
|
||||
@@ -71,4 +71,10 @@ public class BtodayStockPO {
|
||||
/**
|
||||
* 上次更新时间 */
|
||||
Date lastUpdateTime;
|
||||
|
||||
/** 是否锁定 0否 1是 */
|
||||
Integer isLock;
|
||||
|
||||
/** 是否展示 0是 1否 */
|
||||
Integer isShow;
|
||||
}
|
||||
|
||||
@@ -117,15 +117,15 @@ public class InvestingTask {
|
||||
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);
|
||||
String title = n.substring(n.indexOf("html\">") + 6, n.indexOf("<div class=\"short-video-img\">") - 47);
|
||||
|
||||
SiteNews siteNews = new SiteNews();
|
||||
siteNews.setAddTime(new Date());
|
||||
siteNews.setSourceId(id);
|
||||
siteNews.setTitle(title);
|
||||
siteNews.setDescription(time);
|
||||
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));
|
||||
if (list.size() == 0) {
|
||||
newsRepository.save(siteNews);
|
||||
|
||||
@@ -261,6 +261,8 @@ public class Scraper {
|
||||
btodayStock.setSelfUrl(url);
|
||||
btodayStock.setUrl(detailUrl);
|
||||
btodayStock.setLastUpdateTime(new Date());
|
||||
btodayStock.setIsLock(0);
|
||||
btodayStock.setIsShow(0);
|
||||
btodayStockRepo.save(btodayStock);
|
||||
|
||||
/* if (webInfo != null) {
|
||||
|
||||
@@ -167,6 +167,34 @@ public class StockApiController {
|
||||
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线
|
||||
@RequestMapping({"getINDTimeK.do"})
|
||||
@ApiOperation(value = "印度股票K线", httpMethod = "GET")
|
||||
|
||||
Reference in New Issue
Block a user