新增百合会签到(未完成)
移动爬虫代码到对应模块里
This commit is contained in:
@@ -4,13 +4,20 @@ 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.utlis.*;
|
||||
import com.yutou.qqbot.utlis.Log;
|
||||
import com.yutou.qqbot.utlis.RedisTools;
|
||||
import com.yutou.qqbot.utlis.StringUtils;
|
||||
import com.yutou.qqbot.utlis.WebClient;
|
||||
import net.mamoe.mirai.event.events.MessageEvent;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.Calendar;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class TurnipProphet extends Model {
|
||||
public static class TurnipData {
|
||||
@@ -94,7 +101,7 @@ public class TurnipProphet extends Model {
|
||||
}
|
||||
Map<String, String> map = null;
|
||||
try {
|
||||
map = WebClient.getInstance().openTurnip(prices, pattern);
|
||||
map = openTurnip(prices, pattern);
|
||||
sendQQ(map, prices, pattern, qq);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -181,7 +188,7 @@ public class TurnipProphet extends Model {
|
||||
}
|
||||
QQBotManager.getInstance().sendMessage(qq, "已记录,正在预测本周走势...");
|
||||
|
||||
Map<String, String> map = WebClient.getInstance().openTurnip(prices, pattern);
|
||||
Map<String, String> map = openTurnip(prices, pattern);
|
||||
|
||||
String tmp_pattern = sendQQ(map, prices, pattern, qq);
|
||||
if (!StringUtils.isEmpty(tmp_pattern)) {
|
||||
@@ -262,6 +269,75 @@ public class TurnipProphet extends Model {
|
||||
prophet.setData(88, 583819556);
|
||||
|
||||
}
|
||||
|
||||
|
||||
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 driver =WebClient.getInstance().getWebDriver();
|
||||
|
||||
driver.get(url);
|
||||
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
|
||||
Thread.sleep(500);
|
||||
WebElement element = driver.findElement(By.id("output"));
|
||||
List<WebElement> list = element.findElements(By.tagName("tr"));
|
||||
JSONObject pr = new JSONObject();
|
||||
JSONArray array = new JSONArray();
|
||||
if (list.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
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());
|
||||
driver.close();
|
||||
driver.quit();
|
||||
return map;
|
||||
}
|
||||
}
|
||||
/*
|
||||
null.90...........
|
||||
|
||||
Reference in New Issue
Block a user