Compare commits
2 Commits
3eec3a51a3
...
bf1492e8b0
Author | SHA1 | Date | |
---|---|---|---|
bf1492e8b0 | |||
dbb7e3ea68 |
10
pom.xml
10
pom.xml
@ -84,6 +84,16 @@
|
|||||||
<scope>system</scope>
|
<scope>system</scope>
|
||||||
<systemPath>${project.basedir}/libs/json-jena-1.0.jar</systemPath>
|
<systemPath>${project.basedir}/libs/json-jena-1.0.jar</systemPath>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.seleniumhq.selenium</groupId>
|
||||||
|
<artifactId>selenium-java</artifactId>
|
||||||
|
<version>3.141.59</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -36,7 +36,6 @@ public class QQMessageListener extends SimpleListenerHost {
|
|||||||
if (event.getSource().getFromId() == 583819556) {
|
if (event.getSource().getFromId() == 583819556) {
|
||||||
new AdminMessage(qqNumber, event.getMessage().contentToString());
|
new AdminMessage(qqNumber, event.getMessage().contentToString());
|
||||||
}
|
}
|
||||||
System.out.println("isGroup = " + isGroup);
|
|
||||||
for (Class<?> model : Model.classList) {
|
for (Class<?> model : Model.classList) {
|
||||||
if (QQNumberManager.getManager().isUseModel(qqNumber, model)) {
|
if (QQNumberManager.getManager().isUseModel(qqNumber, model)) {
|
||||||
try {
|
try {
|
||||||
|
@ -3,6 +3,7 @@ package com.yutou.qqbot.MessageEvent;
|
|||||||
import com.yutou.qqbot.QQBotManager;
|
import com.yutou.qqbot.QQBotManager;
|
||||||
import com.yutou.qqbot.QQNumberManager;
|
import com.yutou.qqbot.QQNumberManager;
|
||||||
import com.yutou.qqbot.models.Model;
|
import com.yutou.qqbot.models.Model;
|
||||||
|
import com.yutou.qqbot.utlis.RedisTools;
|
||||||
import com.yutou.qqbot.utlis.StringUtils;
|
import com.yutou.qqbot.utlis.StringUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -16,6 +17,9 @@ public class AdminMessage extends Message {
|
|||||||
private static final String MODEL_ADD = "!新增模块";
|
private static final String MODEL_ADD = "!新增模块";
|
||||||
private static final String MODEL_SHOW = "!查看模块";
|
private static final String MODEL_SHOW = "!查看模块";
|
||||||
private static final String MODEL_DEL = "!删除模块";
|
private static final String MODEL_DEL = "!删除模块";
|
||||||
|
|
||||||
|
private static final String SHOW="!列表";
|
||||||
|
private static final String HELP="!help";
|
||||||
}
|
}
|
||||||
|
|
||||||
public AdminMessage(Long qq, String msg) {
|
public AdminMessage(Long qq, String msg) {
|
||||||
@ -27,8 +31,8 @@ public class AdminMessage extends Message {
|
|||||||
for (Class<?> aClass : Model.classList) {
|
for (Class<?> aClass : Model.classList) {
|
||||||
System.err.println(aClass.getName());
|
System.err.println(aClass.getName());
|
||||||
}
|
}
|
||||||
String[] commands;
|
|
||||||
switch (msgGroup[0]) {
|
switch (msgGroup[0]) {
|
||||||
|
case QQCommands.HELP -> QQBotManager.getInstance().sendMessage(qq,Model.getCommands(QQCommands.class).toString());
|
||||||
case QQCommands.POWER_ADD -> {
|
case QQCommands.POWER_ADD -> {
|
||||||
if (msgGroup.length == 1) {
|
if (msgGroup.length == 1) {
|
||||||
StringBuilder builder = Model.getCommands(Model.QQGroupCommands.class);
|
StringBuilder builder = Model.getCommands(Model.QQGroupCommands.class);
|
||||||
@ -106,6 +110,27 @@ public class AdminMessage extends Message {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case QQCommands.SHOW -> {
|
||||||
|
List<Long> users=QQNumberManager.getManager().getNumber();
|
||||||
|
StringBuilder builder=new StringBuilder();
|
||||||
|
for (Long user : users) {
|
||||||
|
builder.append(user).append(":\n");
|
||||||
|
if(QQNumberManager.getManager().isGroup(user)){
|
||||||
|
List<String> list=QQNumberManager.getManager().getUseModel(user);
|
||||||
|
builder.append("模块(").append(list.size()).append("):\n");
|
||||||
|
for (String model : list) {
|
||||||
|
builder.append(model).append("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<String> list=QQNumberManager.getManager().getPower(user);
|
||||||
|
builder.append("权限(").append(list.size()).append("):\n");
|
||||||
|
for (String power : list) {
|
||||||
|
builder.append(power).append("\n");
|
||||||
|
}
|
||||||
|
builder.append("\n");
|
||||||
|
}
|
||||||
|
QQBotManager.getInstance().sendMessage(qq,builder.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.yutou.qqbot;
|
package com.yutou.qqbot;
|
||||||
|
|
||||||
import com.yutou.qqbot.Listeners.QQMessageListener;
|
import com.yutou.qqbot.Listeners.QQMessageListener;
|
||||||
|
import com.yutou.qqbot.models.Animal.TurnipProphet;
|
||||||
import com.yutou.qqbot.models.Commands.Bangumi;
|
import com.yutou.qqbot.models.Commands.Bangumi;
|
||||||
import com.yutou.qqbot.models.Commands.System.*;
|
import com.yutou.qqbot.models.Commands.System.*;
|
||||||
import com.yutou.qqbot.models.Model;
|
import com.yutou.qqbot.models.Model;
|
||||||
@ -33,6 +34,8 @@ public class QQBotManager {
|
|||||||
Model.classList.add(UpdateIP.class);
|
Model.classList.add(UpdateIP.class);
|
||||||
Model.classList.add(Version.class);
|
Model.classList.add(Version.class);
|
||||||
Model.classList.add(Bangumi.class);
|
Model.classList.add(Bangumi.class);
|
||||||
|
|
||||||
|
Model.classList.add(TurnipProphet.class);
|
||||||
}
|
}
|
||||||
private static QQBotManager botManager = null;
|
private static QQBotManager botManager = null;
|
||||||
private Bot bot;
|
private Bot bot;
|
||||||
|
@ -35,7 +35,7 @@ public class QQNumberManager {
|
|||||||
public List<Long> getNumber(){
|
public List<Long> getNumber(){
|
||||||
List<Long> list =new ArrayList<>();
|
List<Long> list =new ArrayList<>();
|
||||||
Jedis jedis=RedisTools.getRedis();
|
Jedis jedis=RedisTools.getRedis();
|
||||||
jedis.select(3);
|
jedis.select(RedisTools.QQBOT_USER);
|
||||||
Set<String> set=jedis.keys("*");
|
Set<String> set=jedis.keys("*");
|
||||||
for (String s : set) {
|
for (String s : set) {
|
||||||
list.add(Long.parseLong(s));
|
list.add(Long.parseLong(s));
|
||||||
|
@ -1,15 +1,213 @@
|
|||||||
package com.yutou.qqbot.models.Animal;
|
package com.yutou.qqbot.models.Animal;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.yutou.qqbot.QQBotManager;
|
||||||
import com.yutou.qqbot.models.Model;
|
import com.yutou.qqbot.models.Model;
|
||||||
|
import com.yutou.qqbot.utlis.*;
|
||||||
|
import net.mamoe.mirai.event.events.MessageEvent;
|
||||||
|
|
||||||
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class TurnipProphet extends Model {
|
||||||
|
public static class TurnipData {
|
||||||
|
public static final String MODEL = "趋势:";
|
||||||
|
public static final String PR = "概率:";
|
||||||
|
public static final String MIX = "保底价:";
|
||||||
|
public static final String MAX = "最高价:";
|
||||||
|
public static final String DAY = "最高日:";
|
||||||
|
|
||||||
|
public static final String MONDAY_UP = "周一上";
|
||||||
|
public static final String MONDAY_DOWN = "周一下";
|
||||||
|
public static final String TUESDAY_UP = "周二上";
|
||||||
|
public static final String TUESDAY_DOWN = "周二下";
|
||||||
|
public static final String WEDNESDAY_UP = "周三上";
|
||||||
|
public static final String WEDNESDAY_DOWN = "周三下";
|
||||||
|
public static final String THURSDAY_UP = "周四上";
|
||||||
|
public static final String THURSDAY_DOWN = "周四下";
|
||||||
|
public static final String FRIDAY_UP = "周五上";
|
||||||
|
public static final String FRIDAY_DOWN = "周五下";
|
||||||
|
public static final String SATURDAY_UP = "周六上";
|
||||||
|
public static final String SATURDAY_DOWN = "周六下";
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int nowTime;
|
||||||
|
|
||||||
public class TurnipProphet extends Model {
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isUserPublic() {
|
public boolean isUserPublic() {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getUsePowers() {
|
public String[] getUsePowers() {
|
||||||
return new String[0];
|
return new String[]{
|
||||||
|
QQFromCommands.TURNIP_PROPHET
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
|
||||||
|
super.onMessage(qq, event, isGroup);
|
||||||
|
int money = -1;
|
||||||
|
try {
|
||||||
|
money = Integer.parseInt(msg.trim());
|
||||||
|
} catch (Exception e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setData(money, event.getSource().getFromId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setData(int money, long qq) {
|
||||||
|
String redisKey = qq + "_turnip";
|
||||||
|
String data = RedisTools.get(redisKey);
|
||||||
|
String pattern = null;
|
||||||
|
JSONObject json;
|
||||||
|
JSONArray array;
|
||||||
|
if (StringUtils.isEmpty(data)) {
|
||||||
|
array = new JSONArray();
|
||||||
|
json = new JSONObject();
|
||||||
|
array.add(-1);
|
||||||
|
array.add(-1);
|
||||||
|
array.add(-1);
|
||||||
|
array.add(-1);
|
||||||
|
array.add(-1);
|
||||||
|
array.add(-1);
|
||||||
|
array.add(-1);
|
||||||
|
array.add(-1);
|
||||||
|
array.add(-1);
|
||||||
|
array.add(-1);
|
||||||
|
array.add(-1);
|
||||||
|
array.add(-1);
|
||||||
|
array.add(-1);
|
||||||
|
} else {
|
||||||
|
json = JSONObject.parseObject(data);
|
||||||
|
array = json.getJSONArray("turnip");
|
||||||
|
}
|
||||||
|
System.err.println(getDay());
|
||||||
|
if(array.getInteger(0)==-1&&getDay()!=0){
|
||||||
|
QQBotManager.getInstance().sendMessage(qq,"没有周日买入信息,本周不收录 :(");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (json.containsKey("old_pattern")) {
|
||||||
|
try {
|
||||||
|
pattern = json.getString("old_pattern");
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (getDay() == 0) {
|
||||||
|
if (json.containsKey("pattern")) {
|
||||||
|
json.put("old_pattern", json.getString("pattern"));
|
||||||
|
pattern = json.getString("pattern");
|
||||||
|
}
|
||||||
|
if (money >= 90 && money <= 110) {
|
||||||
|
array.set(0, money);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (money >= 9 && money <= 660) {
|
||||||
|
System.out.println("array = " + array);
|
||||||
|
System.out.println("array.size() = " + array.size());
|
||||||
|
if (nowTime < 12) {
|
||||||
|
array.set(getDay() * 2 - 1, money);
|
||||||
|
} else {
|
||||||
|
array.set(getDay() * 2, money);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
json.put("turnip", array);
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
for (Object o : array) {
|
||||||
|
builder.append(o).append(".");
|
||||||
|
}
|
||||||
|
builder.append(".".repeat(Math.max(0, (12 - array.size()))));
|
||||||
|
String prices = builder.toString();
|
||||||
|
if (prices.split("\\.").length == 13) {
|
||||||
|
prices = prices.substring(0, prices.length() - 1);
|
||||||
|
}
|
||||||
|
prices = prices.replace("-1", "");
|
||||||
|
json.put("prices", prices);
|
||||||
|
try {
|
||||||
|
if(pattern!=null) {
|
||||||
|
switch (pattern){
|
||||||
|
case "波动型" -> pattern="0";
|
||||||
|
case "大幅上涨(三期型)"-> pattern="1";
|
||||||
|
case "递减型" -> pattern="2";
|
||||||
|
case "小幅上涨(四期型)" -> pattern="3";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QQBotManager.getInstance().sendMessage(qq,"已记录,正在预测本周走势...");
|
||||||
|
Map<String, String> map = WebClient.getInstance().openTurnip(prices, pattern);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
JSONObject pr = JSONObject.parseObject(map.get(TurnipData.MODEL));
|
||||||
|
JSONArray prArray = pr.getJSONArray(TurnipData.MODEL);
|
||||||
|
StringBuilder out = new StringBuilder();
|
||||||
|
out.append("预测结果如下:\n");
|
||||||
|
out.append(TurnipData.MODEL).append(prArray.getJSONObject(0).getString(TurnipData.MODEL)).append("\n");
|
||||||
|
out.append(TurnipData.PR).append(prArray.getJSONObject(0).getString(TurnipData.PR)).append("\n");
|
||||||
|
|
||||||
|
out.append(TurnipData.MIX).append(map.get(TurnipData.MIX)).append("\n")
|
||||||
|
.append(TurnipData.MAX).append(map.get(TurnipData.MAX)).append("\n")
|
||||||
|
.append(TurnipData.DAY).append(map.get(TurnipData.DAY)).append("\n")
|
||||||
|
.append("-------------").append("\n")
|
||||||
|
.append(TurnipData.MONDAY_UP).append(map.get(TurnipData.MONDAY_UP)).append(" | ")
|
||||||
|
.append(TurnipData.MONDAY_DOWN).append(map.get(TurnipData.MONDAY_DOWN)).append("\n")
|
||||||
|
.append(TurnipData.TUESDAY_UP).append(map.get(TurnipData.TUESDAY_UP)).append(" | ")
|
||||||
|
.append(TurnipData.TUESDAY_DOWN).append(map.get(TurnipData.TUESDAY_DOWN)).append("\n")
|
||||||
|
.append(TurnipData.WEDNESDAY_UP).append(map.get(TurnipData.WEDNESDAY_UP)).append(" | ")
|
||||||
|
.append(TurnipData.WEDNESDAY_DOWN).append(map.get(TurnipData.WEDNESDAY_DOWN)).append("\n")
|
||||||
|
.append(TurnipData.THURSDAY_UP).append(map.get(TurnipData.THURSDAY_UP)).append(" | ")
|
||||||
|
.append(TurnipData.THURSDAY_DOWN).append(map.get(TurnipData.THURSDAY_DOWN)).append("\n")
|
||||||
|
.append(TurnipData.FRIDAY_UP).append(map.get(TurnipData.FRIDAY_UP)).append(" | ")
|
||||||
|
.append(TurnipData.FRIDAY_DOWN).append(map.get(TurnipData.FRIDAY_DOWN)).append("\n")
|
||||||
|
.append(TurnipData.SATURDAY_UP).append(map.get(TurnipData.SATURDAY_UP)).append(" | ")
|
||||||
|
.append(TurnipData.SATURDAY_DOWN).append(map.get(TurnipData.SATURDAY_DOWN)).append("\n")
|
||||||
|
;
|
||||||
|
out.append("------------").append("\n");
|
||||||
|
out.append("总概率:").append("\n");
|
||||||
|
|
||||||
|
for (Object o : prArray) {
|
||||||
|
JSONObject tmp = (JSONObject) o;
|
||||||
|
out.append(tmp.getString(TurnipData.MODEL)).append(":").append(tmp.getString(TurnipData.PR)).append("\n");
|
||||||
|
}
|
||||||
|
out.append("------------").append("\n");
|
||||||
|
out.append("祝好运 :)");
|
||||||
|
json.put("pattern", prArray.getJSONObject(0).getString(TurnipData.MODEL));
|
||||||
|
RedisTools.set(redisKey, json.toJSONString());
|
||||||
|
Log.i("TurnipProphet",out.toString());
|
||||||
|
QQBotManager.getInstance().sendMessage(qq,out.toString());
|
||||||
|
} catch (Exception e) {
|
||||||
|
setData(money, qq);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTime(String time) {
|
||||||
|
super.onTime(time);
|
||||||
|
nowTime = Integer.parseInt(time.split(":")[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getDay() {
|
||||||
|
return Calendar.getInstance().get(Calendar.DAY_OF_WEEK)-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
TurnipProphet prophet = new TurnipProphet();
|
||||||
|
prophet.setData(88, 583819556);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
null.90...........
|
||||||
|
null.97...........
|
||||||
|
|
||||||
|
null.1!.1@.2!.2@.3!.3@.4!.4@.5!.5@.90.
|
||||||
|
null.1!.1@.2!.2@.3!.3@.4!.4@.5!.5@.6!.90.
|
||||||
|
*/
|
@ -35,7 +35,7 @@ public abstract class Model implements ModelInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class QQFromCommands {
|
public static class QQFromCommands {
|
||||||
public static final String ADD_POWER = "大头菜";
|
public static final String TURNIP_PROPHET = "大头菜";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
|
|
||||||
public class RedisTools {
|
public class RedisTools {
|
||||||
|
public static final int QQBOT_USER = 3;
|
||||||
private static boolean isNotInstallRedis = false;
|
private static boolean isNotInstallRedis = false;
|
||||||
private static String host;
|
private static String host;
|
||||||
private static int port;
|
private static int port;
|
||||||
@ -78,11 +79,11 @@ public class RedisTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean set(Object key, String value) {
|
public static boolean set(Object key, String value) {
|
||||||
return set(3, key+"", value);
|
return set(QQBOT_USER, key+"", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean set(String key, String value, long timeout) {
|
public static boolean set(String key, String value, long timeout) {
|
||||||
return set(key, value, timeout,3);
|
return set(key, value, timeout,QQBOT_USER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String get(String key, int dbIndex) {
|
public static String get(String key, int dbIndex) {
|
||||||
@ -102,11 +103,11 @@ public class RedisTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String get(Object key) {
|
public static String get(Object key) {
|
||||||
return get(key+"", 3);
|
return get(key+"", QQBOT_USER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean remove(String key) {
|
public static boolean remove(String key) {
|
||||||
return remove(key,3);
|
return remove(key,QQBOT_USER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeLoginState(String uid) {
|
public static void removeLoginState(String uid) {
|
||||||
@ -127,7 +128,7 @@ public class RedisTools {
|
|||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
public static boolean exists(Object key,String value){
|
public static boolean exists(Object key,String value){
|
||||||
return exists(3,key,value);
|
return exists(QQBOT_USER,key,value);
|
||||||
}
|
}
|
||||||
public static boolean exists(int db,Object key, String value) {
|
public static boolean exists(int db,Object key, String value) {
|
||||||
if (isNotInstallRedis) {
|
if (isNotInstallRedis) {
|
||||||
@ -194,13 +195,9 @@ public class RedisTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void pullMsg(String channel, String msg) {
|
public static void pullMsg(String channel, String msg) {
|
||||||
Log.i("1");
|
|
||||||
Jedis jedis = getPoolRedis();
|
Jedis jedis = getPoolRedis();
|
||||||
Log.i("2");
|
|
||||||
jedis.publish(channel, msg);
|
jedis.publish(channel, msg);
|
||||||
Log.i("3");
|
|
||||||
jedis.close();
|
jedis.close();
|
||||||
Log.i("4");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean init = false;
|
private static boolean init = false;
|
||||||
|
115
src/main/java/com/yutou/qqbot/utlis/WebClient.java
Normal file
115
src/main/java/com/yutou/qqbot/utlis/WebClient.java
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
package com.yutou.qqbot.utlis;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.yutou.qqbot.models.Animal.TurnipProphet;
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.WebDriver;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.openqa.selenium.chrome.ChromeDriver;
|
||||||
|
import org.openqa.selenium.chrome.ChromeOptions;
|
||||||
|
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||||
|
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class WebClient {
|
||||||
|
private static WebClient client;
|
||||||
|
|
||||||
|
|
||||||
|
public static WebClient getInstance() {
|
||||||
|
if (client == null) {
|
||||||
|
client = new WebClient();
|
||||||
|
}
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
private WebClient() {
|
||||||
|
System.setProperty("webdriver.chrome.driver",
|
||||||
|
"E:\\GoogleChromeDriver\\chromedriver.exe");
|
||||||
|
java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.OFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> openTurnip(String prices, String pattern) throws Exception {
|
||||||
|
String url=String.format("https://turnipprophet.io?prices=%s%s",
|
||||||
|
prices,
|
||||||
|
pattern == null ? "" : "&pattern=" + pattern
|
||||||
|
);
|
||||||
|
System.out.println("url = " + url);
|
||||||
|
LinkedHashMap<String, String> map = new LinkedHashMap<>();
|
||||||
|
WebDriver webDriver = new ChromeDriver(getOptions());
|
||||||
|
|
||||||
|
webDriver.get(url);
|
||||||
|
webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
|
||||||
|
Thread.sleep(500);
|
||||||
|
|
||||||
|
WebElement element = webDriver.findElement(By.id("output"));
|
||||||
|
List<WebElement> list = element.findElements(By.tagName("tr"));
|
||||||
|
JSONObject pr = new JSONObject();
|
||||||
|
JSONArray array = new JSONArray();
|
||||||
|
|
||||||
|
for (WebElement webElement : list) {
|
||||||
|
String[] tmp;
|
||||||
|
try {
|
||||||
|
tmp = webElement.getText().replace(" ~ ", "~").split(" ");
|
||||||
|
} catch (Exception e) {
|
||||||
|
//e.printStackTrace();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ("所有趋势".equals(tmp[0])) {
|
||||||
|
map.put(TurnipProphet.TurnipData.MONDAY_UP, tmp[3]);
|
||||||
|
map.put(TurnipProphet.TurnipData.MONDAY_DOWN, tmp[4]);
|
||||||
|
map.put(TurnipProphet.TurnipData.TUESDAY_UP, tmp[5]);
|
||||||
|
map.put(TurnipProphet.TurnipData.TUESDAY_DOWN, tmp[6]);
|
||||||
|
map.put(TurnipProphet.TurnipData.WEDNESDAY_UP, tmp[7]);
|
||||||
|
map.put(TurnipProphet.TurnipData.WEDNESDAY_DOWN, tmp[8]);
|
||||||
|
map.put(TurnipProphet.TurnipData.THURSDAY_UP, tmp[9]);
|
||||||
|
map.put(TurnipProphet.TurnipData.THURSDAY_DOWN, tmp[10]);
|
||||||
|
map.put(TurnipProphet.TurnipData.FRIDAY_UP, tmp[11]);
|
||||||
|
map.put(TurnipProphet.TurnipData.FRIDAY_DOWN, tmp[12]);
|
||||||
|
map.put(TurnipProphet.TurnipData.SATURDAY_UP, tmp[13]);
|
||||||
|
map.put(TurnipProphet.TurnipData.SATURDAY_DOWN, tmp[14]);
|
||||||
|
|
||||||
|
map.put(TurnipProphet.TurnipData.MIX, tmp[15]);
|
||||||
|
map.put(TurnipProphet.TurnipData.MAX, tmp[16]);
|
||||||
|
} else {
|
||||||
|
if (!array.toJSONString().contains(tmp[0])) {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put(TurnipProphet.TurnipData.MODEL, tmp[0]);
|
||||||
|
json.put(TurnipProphet.TurnipData.PR, tmp[1]);
|
||||||
|
array.add(json);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (String key : map.keySet()) {
|
||||||
|
System.err.println("记录最高日:"+map.get(key)+" > "+key);
|
||||||
|
if (!key.equals(TurnipProphet.TurnipData.MAX) &&
|
||||||
|
map.get(key).contains(map.get(TurnipProphet.TurnipData.MAX))) {
|
||||||
|
map.put(TurnipProphet.TurnipData.DAY, key);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pr.put(TurnipProphet.TurnipData.MODEL, array);
|
||||||
|
map.put(TurnipProphet.TurnipData.MODEL, pr.toJSONString());
|
||||||
|
webDriver.close();
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ChromeOptions getOptions() {
|
||||||
|
ChromeOptions options = new ChromeOptions();
|
||||||
|
options.addArguments("disable-infobars");
|
||||||
|
options.addArguments("blink-settings=imagesEnabled=false");
|
||||||
|
options.addArguments("headless");
|
||||||
|
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user