Browse Source

backup 001

master
独行之狼 4 years ago
parent
commit
2579cdaae7
  1. BIN
      fr-plugin-MarketUpdate-1.0/fr-plugin-MarketUpdate-1.0.jar
  2. BIN
      install/fr-plugin-MarketUpdate-1.0.zip
  3. 8
      src/main/java/com/fr/plugin/market/update/FRFinanceFunction.java
  4. 41
      src/main/java/com/fr/plugin/market/update/FRForwardMarket.java
  5. 44
      src/main/java/com/fr/plugin/market/update/FRGoldSilver.java
  6. 40
      src/main/java/com/fr/plugin/market/update/FRMarketIndex.java
  7. 34
      src/main/java/com/fr/plugin/market/update/FRStockMarket.java
  8. 88
      src/main/java/com/fr/plugin/market/update/FunConstants.java
  9. 26
      src/main/java/com/fr/plugin/market/update/TestFun.java
  10. 0
      src/main/resources/com/fr/com.fr.plugin.market.update/imageProcess.properties
  11. 0
      src/main/resources/com/fr/com.fr.plugin.market.update/imageProcess_zh_CN.properties

BIN
fr-plugin-MarketUpdate-1.0/fr-plugin-MarketUpdate-1.0.jar

Binary file not shown.

BIN
install/fr-plugin-MarketUpdate-1.0.zip

Binary file not shown.

8
src/main/java/com/fr/plugin/market/update/FRFinanceFunction.java

@ -10,8 +10,12 @@ public class FRFinanceFunction extends AbstractFunctionDefContainer {
@Focus(id=FunConstants.PLUGIN_ID, text="金融行情数据")
public FunctionDef[] getFunctionDefs() {
return new FunctionDef[]{
new FunctionDef("FRExchangeRate", "功能:。", FRExchangeRate.class.getName()),
new FunctionDef("FRStockMarket", "功能:。", FRStockMarket.class.getName())
new FunctionDef("FRExchangeRate", "功能:\n获取外汇市数据。\n参数1:\n外汇货币代码,如USD、CNY。\n参数2:\n外汇货币代码,如USD、CNY等。\n示例:\nFRExchangeRate(\"USD\",\"CNY\"),表示获取当前1美竞换多少人民币。", FRExchangeRate.class.getName()),
new FunctionDef("FRStockMarket", "功能:\n获取股票市场数据。\n参数1:\n上海或深圳。\n参数2:\n股票代码,\n参数3:股票具体参数,如:\"今日开盘价\",\"昨日收盘价\",\"当前价格\",\"今日最高价\",\"今日最低价\",\"竞买价\",\"竞卖价\",\"成交股票数\",\"成交金额\",\"买一手数\",\"买一报价\",\"买二手数\",\"买二报价\",\"买三手数\",\"买三报价\",\"买四手数\",\"买四报价\",\"买五手数\",\"买五报价\",\"卖一手数\",\"卖一报价\",\"卖二手数\",\"卖二报价\",\"卖三手数\",\"卖三报价\",\"卖四手数\",\"卖四报价\",\"卖五手数\",\"卖五报价\",\n示例:FRStockMarket(\"深圳\",\"002307\",\"今日开盘价\")。", FRStockMarket.class.getName()),
new FunctionDef("FRGoldSilver", "功能:\n获取国际金银行情,国际金价,国际金银行情,国际金价。\n参数1:\n\"伦敦金\",\"伦敦银\",\"COMEX黄金\",\"COMEX白银\",\"黄金T+D\",\"白银T+D\"。\n参数2:\n\"最新价\",\"涨跌\",\"涨跌幅\",\"最高价\",\"最低价\",\"今开价\",\"昨收价\"。\n示例:\nFRGoldSilver(\"白银T+D\",\"最新价\")。", FRGoldSilver.class.getName()),
new FunctionDef("FRForwardMarket", "功能:\n期货市场数据,包括:WTI原油,伦敦布伦特原油,黄金, 白银,天然气,铜,美国大豆。\n参数1:\n \"WTI原油\",\"伦敦布伦特原油\",\"黄金\",\"白银\",\"天然气\",\"铜\",\"美国大豆\"。\n参数2:\n\"最新\",\"昨收\",\"开盘\",\" 最低\",\"最高\"。\n示例:FRForwardMarket(\"伦敦布伦特原油\",\"最高\")。", FRForwardMarket.class.getName()),
new FunctionDef("FRMarketIndex", "功能:\n获取7×24小时权威及时股票指数行情:大盘指数、港股指数、美股指数、期货指数、全球股脂,今日股市指数尽在掌握。\n参数1:\n \"上证指数\",\"富时中国A50指数\",\"恒生指数\",\"日经225\",\"道琼斯30(F)\",\"美国标普500(F)\",\"美元指数期货\"。\n参数2:\n\"最新\",\"昨收\",\"开盘\",\" 最低\",\"最高\"。\n示例:FRMarketIndex(\"道琼斯30(F)\",\"最新\")。", FRMarketIndex.class.getName()),
};
}

41
src/main/java/com/fr/plugin/market/update/FRForwardMarket.java

@ -0,0 +1,41 @@
package com.fr.plugin.market.update;
import com.fr.intelli.record.Focus;
import com.fr.intelli.record.Original;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.script.AbstractFunction;
import com.fr.stable.Primitive;
import com.fr.stable.fun.Authorize;
import java.io.IOException;
@EnableMetrics
@Authorize(callSignKey = FunConstants.PLUGIN_ID)
public class FRForwardMarket extends AbstractFunction {
@Focus(id = FunConstants.PLUGIN_ID, text = "Plugin-Test_Function_FRForwardMarket", source = Original.PLUGIN)
public Object run(Object[] args) {
if(!FunConstants.author()){
return FunConstants.AUTHOR_ERROR;
}
String checkRes = FunConstants.CheckArgs(args,2 );
if (!checkRes.equals(FunConstants.CHECK_PASS)) {
return Primitive.ERROR_VALUE + checkRes;
}
String forwardType = args[0].toString();
String forwardArgs = args[1].toString();
String result;
try {
result= FunConstants.GetForwardData(forwardType,forwardArgs);
} catch (IOException e) {
return Primitive.ERROR_VALUE;
}
if(result==FunConstants.ARGS_ERROR){
return Primitive.ERROR_VALUE;
}
return result;
}
}

44
src/main/java/com/fr/plugin/market/update/FRGoldSilver.java

@ -0,0 +1,44 @@
package com.fr.plugin.market.update;
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;
@EnableMetrics
@Authorize(callSignKey = FunConstants.PLUGIN_ID)
public class FRGoldSilver extends AbstractFunction {
@Focus(id = FunConstants.PLUGIN_ID, text = "Plugin-Test_Function_FRGoldMarket", source = Original.PLUGIN)
public Object run(Object[] args) {
if(!FunConstants.author()){
return FunConstants.AUTHOR_ERROR;
}
String checkRes = FunConstants.CheckArgs(args,2 );
if (!checkRes.equals(FunConstants.CHECK_PASS)) {
return Primitive.ERROR_VALUE + checkRes;
}
String goldType = args[0].toString();
String goldArgs = args[1].toString();
String result;
try {
result= FunConstants.GetGoldData(goldType,goldArgs);
} catch (IOException e) {
return Primitive.ERROR_VALUE;
}
if(result==FunConstants.ARGS_ERROR){
return Primitive.ERROR_VALUE;
}
return result;
}
}

40
src/main/java/com/fr/plugin/market/update/FRMarketIndex.java

@ -0,0 +1,40 @@
package com.fr.plugin.market.update;
import com.fr.intelli.record.Focus;
import com.fr.intelli.record.Original;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.script.AbstractFunction;
import com.fr.stable.Primitive;
import com.fr.stable.fun.Authorize;
import java.io.IOException;
@EnableMetrics
@Authorize(callSignKey = FunConstants.PLUGIN_ID)
public class FRMarketIndex extends AbstractFunction {
@Focus(id = FunConstants.PLUGIN_ID, text = "Plugin-Test_Function_FRMarketIndex", source = Original.PLUGIN)
public Object run(Object[] args) {
if(!FunConstants.author()){
return FunConstants.AUTHOR_ERROR;
}
String checkRes = FunConstants.CheckArgs(args,2 );
if (!checkRes.equals(FunConstants.CHECK_PASS)) {
return Primitive.ERROR_VALUE + checkRes;
}
String indexType = args[0].toString();
String indexArgs = args[1].toString();
String result;
try {
result= FunConstants.GetIndexData(indexType,indexArgs);
} catch (IOException e) {
return Primitive.ERROR_VALUE;
}
if(result==FunConstants.ARGS_ERROR){
return Primitive.ERROR_VALUE;
}
return result;
}
}

34
src/main/java/com/fr/plugin/market/update/FRStockMarket.java

@ -11,6 +11,7 @@ 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;
@ -19,10 +20,10 @@ import java.util.regex.Pattern;
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()){
if (!FunConstants.author()) {
return FunConstants.AUTHOR_ERROR;
}
String checkRes = FunConstants.CheckArgs(args,3 );
String checkRes = FunConstants.CheckArgs(args, 3);
if (!checkRes.equals(FunConstants.CHECK_PASS)) {
return Primitive.ERROR_VALUE + checkRes;
}
@ -30,39 +31,40 @@ public class FRStockMarket extends AbstractFunction {
String city = args[0].toString();
String stockCode = args[1].toString();
String stockArgs = args[2].toString();
FineLoggerFactory.getLogger().info("stockArgs:{}",stockArgs);
FineLoggerFactory.getLogger().info("stockArgs:{}", stockArgs);
String result;
try {
result= getStock(city,stockCode,stockArgs);
result = getStock(city, stockCode, stockArgs);
} catch (IOException e) {
FineLoggerFactory.getLogger().info("getStock");
return Primitive.ERROR_VALUE;
}
if(result==FunConstants.ARGS_ERROR){
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");
private final String getStock(String city, String stockCode, String stockArgs) throws IOException {
if (!ArrayUtils.contains(FunConstants.StockCity, city) || !ArrayUtils.contains(FunConstants.StockArgs, stockArgs)) {
return FunConstants.ARGS_ERROR;
}
if(!FunConstants.CheckStockCode(stockCode)){
FineLoggerFactory.getLogger().info("isMatched");
if (!FunConstants.CheckStockCode(stockCode)) {
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 cityCode = city.equals("上海") ? "sh" : "sz";
final String CHINA_BANK_URI = "http://hq.sinajs.cn/list=" + cityCode + stockCode;
return getStockData(CHINA_BANK_URI, stockArgs);
}
private String getStockData(String url, String stockArgs) throws IOException {
Document doc = Jsoup.connect(url).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;
}
}

88
src/main/java/com/fr/plugin/market/update/FunConstants.java

@ -4,9 +4,12 @@ import com.fr.plugin.PluginLicenseManager;
import com.fr.plugin.context.PluginContexts;
import com.fr.stable.ArrayUtils;
import com.fr.stable.fun.Authorize;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
//import static com.fr.design.i18n.Toolkit.i18nText;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.regex.Pattern;
@Authorize(callSignKey = FunConstants.PLUGIN_ID)
@ -15,9 +18,13 @@ public class FunConstants {
static final String AUTHOR_ERROR = "Plugin.Function.Market_upate_AUTHOR_ERROR";
static final String CHECK_PASS = "Plugin.Function.ImagProcess_CHECK_PASS";
static final String ARGS_ERROR= "args_error";
//外汇
static final String[] CurrencyCodeList = new String[]{
"USD", "AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BRL", "BSD", "BTN", "BWP", "BYN", "BZD", "CAD", "CDF", "CHF", "CLP", "CNY", "COP", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "FOK", "GBP", "GEL", "GGP", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "IMP", "INR", "IQD", "IRR", "ISK", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KID", "KMF", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRU", "MUR", "MVR", "MWK", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLL", "SOS", "SRD", "SSP", "STN", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TVD", "TWD", "TZS", "UAH", "UGX", "UYU", "UZS", "VES", "VND", "VUV", "WST", "XAF", "XCD", "XDR", "XOF", "XPF", "YER", "ZAR", "ZMW"
};
//股市
static final String[] StockArgs={
"股票名字","今日开盘价","昨日收盘价","当前价格","今日最高价","今日最低价","竞买价","竞卖价","成交股票数","成交金额","买一手数","买一报价","买二手数","买二报价","买三手数","买三报价","买四手数","买四报价","买五手数","买五报价","卖一手数","卖一报价","卖二手数","卖二报价","卖三手数","卖三报价","卖四手数","卖四报价","卖五手数","卖五报价","日期","时间"
};
@ -25,6 +32,34 @@ public class FunConstants {
"上海","深圳"
};
//金银
static final String[] GoldType={
"伦敦金","伦敦银","COMEX黄金","COMEX白银","黄金T+D","白银T+D"
};
static final String[] GoldName={
"最新价","涨跌","涨跌幅","最高价","最低价","今开价","昨收价"
};
//期货
static final String[] ForwardType={
"WTI原油","伦敦布伦特原油","黄金","白银","天然气","铜","美国大豆"
};
static final String[] ForwardURL={
"crude-oil","brent-oil","gold","silver","natural-gas","copper","us-soybeans"
};
static final String[] ForwardAndIndexArgs={
"最新","昨收","开盘"," 最低","最高"
};
//指数
static final String[] IndexType={
"上证指数","富时中国A50指数","恒生指数","日经225","道琼斯30(F)","美国标普500(F)","美元指数期货"
};
static final String[] IndexURL={
"shanghai-composite","ftse-china-a50","hang-sen-40","japan-ni225","us-30-futures","us-spx-500-futures","us-dollar-index"
};
static final boolean author() {
return PluginLicenseManager.getInstance().getPluginLicenseByID(PLUGIN_ID).isAvailable();
}
@ -35,7 +70,7 @@ public class FunConstants {
return isMatched;
}
static String CheckArgs(Object[] args, int num) {
static final String CheckArgs(Object[] args, int num) {
String res = FunConstants.CHECK_PASS;
int len = ArrayUtils.getLength(args);
if (len != num) {
@ -43,4 +78,55 @@ public class FunConstants {
}
return res;
}
static final String GetGoldData(String goldType ,String goldArgs) throws IOException {
if(!ArrayUtils.contains(GoldType,goldType)||!ArrayUtils.contains(GoldName,goldArgs)){
return ARGS_ERROR;
}
final String GOLD_URI = "http://www.dyhjw.com/guojijin.html";
Document doc = Jsoup.connect(GOLD_URI).ignoreContentType(true).get();
String r=doc.getElementsByClass("gold_price_data").first().select("[code='XAU']").first().text();
String[] goldData=r.split(" ");
final int goldArgsIndex = ArrayUtils.indexOf(GoldName, goldArgs)+1;
return goldData[goldArgsIndex];
}
static final String GetForwardData(String forwardType ,String forwardArgs) throws IOException {
if(!ArrayUtils.contains(ForwardType,forwardType)||!ArrayUtils.contains(ForwardAndIndexArgs,forwardArgs)){
return ARGS_ERROR;
}
final int i = ArrayUtils.indexOf(ForwardType, forwardType);
final String CHINA_BANK_URI = "https://cn.investing.com/commodities/"+ForwardURL[i];
String agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36 Edg/89.0.774.54";
Document doc = Jsoup.connect(CHINA_BANK_URI).ignoreContentType(true).userAgent(agent).get();
if("最新".equals(forwardArgs)){
return doc.getElementById("last_last").text();
}
final String summaryData = doc.getElementById("quotes_summary_secondary_data").select("[ dir=\"ltr\"]").text().replaceAll("- ","");
final String[] split = summaryData.split(" ");
final int argsIndex = ArrayUtils.indexOf(ForwardAndIndexArgs, forwardArgs);
return split[argsIndex-1];
}
static final String GetIndexData(String indexType ,String indexdArgs) throws IOException {
if(!ArrayUtils.contains(IndexType,indexType)||!ArrayUtils.contains(ForwardAndIndexArgs,indexdArgs)){
return ARGS_ERROR;
}
final int i = ArrayUtils.indexOf(IndexType, indexType);
final String CHINA_BANK_URI = "https://cn.investing.com/indices/"+IndexURL[i];
String agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36 Edg/89.0.774.54";
Document doc = Jsoup.connect(CHINA_BANK_URI).ignoreContentType(true).userAgent(agent).get();
if("最新".equals(indexdArgs)){
return doc.getElementById("last_last").text();
}
final String summaryData = doc.getElementById("quotes_summary_secondary_data").select("[ dir=\"ltr\"]").text().replaceAll("- ","");
final String[] split = summaryData.split(" ");
final int argsIndex = ArrayUtils.indexOf(ForwardAndIndexArgs, indexdArgs);
return split[argsIndex-1];
}
}

26
src/main/java/com/fr/plugin/market/update/TestFun.java

@ -1,6 +1,7 @@
package com.fr.plugin.market.update;
import com.alibaba.fastjson.JSONObject;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.market.update.FunConstants;
import com.fr.stable.ArrayUtils;
import org.jsoup.Jsoup;
@ -36,21 +37,24 @@ public class TestFun {
//// JSONObject j=JSONObject.parseObject(s);
// System.out.println(s);
final String CHINA_BANK_URI = "http://hq.sinajs.cn/list=sh600928";
if((!ArrayUtils.contains(FunConstants.CurrencyCodeList,"USD"))||(!ArrayUtils.contains(FunConstants.CurrencyCodeList,"USD"))){
System.out.printf("00");
}
final String CHINA_BANK_URI = "https://cn.investing.com/currencies/us-dollar-index";
// if((!ArrayUtils.contains(FunConstants.CurrencyCodeList,"USD"))||(!ArrayUtils.contains(FunConstants.CurrencyCodeList,"USD"))){
// System.out.printf("00");
// }
Document doc = Jsoup.connect(CHINA_BANK_URI).ignoreContentType(true).get();
Document doc = Jsoup.connect(CHINA_BANK_URI).ignoreContentType(true).userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36 Edg/89.0.774.54").get();
// final String body = doc.getElementsByTag("body").first().text();
// JSONObject j=JSONObject.parseObject(body);
// System.out.printf(JSONObject.parseObject(j.get("conversion_rates").toString()).get("CNY").toString());
final String s = doc.text().split("\"")[1];
final String[] stocks = s.split(",");
final int stockArgsIndex = ArrayUtils.indexOf(FunConstants.StockArgs, "日期");
final String regExp="^002[\\d]{3}|000[\\d]{3}|300[\\d]{3}|600[\\d]{3}|60[\\d]{4}$ ";
final boolean isMatched = Pattern.compile(regExp).matcher("600928").matches();
System.out.printf("isMatched:"+isMatched);
// final String s = doc.text().split("\"")[1];
// final String[] stocks = s.split(",");
// final int stockArgsIndex = ArrayUtils.indexOf(FunConstants.StockArgs, "日期");
// final String regExp="^002[\\d]{3}|000[\\d]{3}|300[\\d]{3}|600[\\d]{3}|60[\\d]{4}$ ";
// final boolean isMatched = Pattern.compile(regExp).matcher("600928").matches();
// String r=doc.getElementsByClass("gold_price_data").first().select("[code='XAU']").first().text();
// String[] ra=r.split(" ");
FineLoggerFactory.getLogger().info(doc.getElementById("last_last").text());
FineLoggerFactory.getLogger().info(doc.getElementById("quotes_summary_secondary_data").select("[ dir=\"ltr\"]").text().replaceAll("- ",""));
}
}

0
src/main/resources/com/fr/com.fr.plugin.imageProcess/imageProcess.properties → src/main/resources/com/fr/com.fr.plugin.market.update/imageProcess.properties

0
src/main/resources/com/fr/com.fr.plugin.imageProcess/imageProcess_zh_CN.properties → src/main/resources/com/fr/com.fr.plugin.market.update/imageProcess_zh_CN.properties

Loading…
Cancel
Save