独行之狼
4 years ago
8 changed files with 116 additions and 20 deletions
Binary file not shown.
Binary file not shown.
@ -0,0 +1,68 @@
|
||||
package com.fr.plugin.market.update; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.fr.intelli.record.Focus; |
||||
import com.fr.intelli.record.Original; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
import com.fr.script.AbstractFunction; |
||||
import com.fr.stable.ArrayUtils; |
||||
import com.fr.stable.Primitive; |
||||
import com.fr.stable.fun.Authorize; |
||||
import org.jsoup.Jsoup; |
||||
import org.jsoup.nodes.Document; |
||||
import java.io.IOException; |
||||
import java.util.regex.Pattern; |
||||
|
||||
@EnableMetrics |
||||
@Authorize(callSignKey = FunConstants.PLUGIN_ID) |
||||
public class FRStockMarket extends AbstractFunction { |
||||
@Focus(id = FunConstants.PLUGIN_ID, text = "Plugin-Test_Function_FRStockMarket", source = Original.PLUGIN) |
||||
public Object run(Object[] args) { |
||||
if(!FunConstants.author()){ |
||||
return FunConstants.AUTHOR_ERROR; |
||||
} |
||||
String checkRes = FunConstants.CheckArgs(args,3 ); |
||||
if (!checkRes.equals(FunConstants.CHECK_PASS)) { |
||||
return Primitive.ERROR_VALUE + checkRes; |
||||
} |
||||
|
||||
String city = args[0].toString(); |
||||
String stockCode = args[1].toString(); |
||||
String stockArgs = args[2].toString(); |
||||
FineLoggerFactory.getLogger().info("stockArgs:{}",stockArgs); |
||||
String result; |
||||
try { |
||||
result= getStock(city,stockCode,stockArgs); |
||||
} catch (IOException e) { |
||||
FineLoggerFactory.getLogger().info("getStock"); |
||||
return Primitive.ERROR_VALUE; |
||||
} |
||||
if(result==FunConstants.ARGS_ERROR){ |
||||
return Primitive.ERROR_VALUE; |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
private final String getStock(String city ,String stockCode,String stockArgs) throws IOException { |
||||
if(!ArrayUtils.contains(FunConstants.StockCity,city)||!ArrayUtils.contains(FunConstants.StockArgs,stockArgs)){ |
||||
FineLoggerFactory.getLogger().info("contains"); |
||||
return FunConstants.ARGS_ERROR; |
||||
} |
||||
|
||||
if(!FunConstants.CheckStockCode(stockCode)){ |
||||
FineLoggerFactory.getLogger().info("isMatched"); |
||||
return FunConstants.ARGS_ERROR; |
||||
} |
||||
final String cityCode=city.equals("上海")?"sh":"sz"; |
||||
final String CHINA_BANK_URI = "http://hq.sinajs.cn/list="+cityCode+stockCode; |
||||
FineLoggerFactory.getLogger().info("CHINA_BANK_URI:{}",CHINA_BANK_URI); |
||||
Document doc = Jsoup.connect(CHINA_BANK_URI).ignoreContentType(true).get(); |
||||
final String s = doc.text().split("\"")[1]; |
||||
final String[] stocks = s.split(","); |
||||
final int stockArgsIndex = ArrayUtils.indexOf(FunConstants.StockArgs, stockArgs); |
||||
final String result = stocks[stockArgsIndex]; |
||||
return result; |
||||
|
||||
} |
||||
} |
Loading…
Reference in new issue