Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
KeKe12030 committed Feb 9, 2020
1 parent 0ce6083 commit 3e5ce00
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 116 deletions.
Binary file modified bin/cn/mcplugin/kqjcq/JsonInfo.class
Binary file not shown.
Binary file modified bin/cn/mcplugin/kqjcq/Main.class
Binary file not shown.
Binary file modified bin/cn/mcplugin/kqjcq/SickWebSite.class
Binary file not shown.
142 changes: 105 additions & 37 deletions src/cn/mcplugin/kqjcq/JsonInfo.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package cn.mcplugin.kqjcq;

import org.json.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.HTTP;
import org.json.JSONArray;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
@SuppressWarnings("all")
public class JsonInfo implements Runnable{
public static String jsonStr = null;
Expand All @@ -21,47 +16,120 @@ public static void main(String[] args) {
getDocument();
System.out.println(getGlobalInfo());
}

public String getCityInfo(String city) {return null;}

public static String getGlobalInfo() {
//System.out.println(jsonStr);
JSONObject j = new JSONObject(jsonStr);
JSONObject arr = j.getJSONObject("data");
String finalStr = "数据更新至:"+arr.getString("date")+"\n"
+"确诊病例:"+arr.getInt("diagnosed")+"\n"
+"疑似病例:"+arr.getInt("suspect")+"\n"
+"治愈人数:"+arr.getInt("cured")+"\n"
+"死亡病例:"+arr.getInt("death");


+"确诊病例:"+arr.getInt("diagnosed")+" 新增:+"+arr.getInt("diagnosedIncr")+"\n"
+"严重病例:"+arr.getInt("serious")+" 新增:+"+arr.getInt("seriousIncr")+"\n"
+"疑似病例:"+arr.getInt("suspect")+" 新增:+"+arr.getInt("suspectIncr")+"\n"
+"治愈人数:"+arr.getInt("cured")+" 新增:+"+arr.getInt("curedIncr")+"\n"
+"死亡病例:"+arr.getInt("death")+" 新增:+"+arr.getInt("deathIncr");
return finalStr;



}
public static boolean isJsonOK(){
if(jsonStr == null) {
getDocument();
}
JSONObject js = new JSONObject(jsonStr);

if(js.getInt("errcode")!=0) {
return false;
}
return true;
}
public static void getDocument() {
//实例化defaultHttpClient
DefaultHttpClient hc=new DefaultHttpClient();
try {
//实例化post方式访问并且把路径放入
HttpPost httppost=new HttpPost(api);
//把需要的参数传入
//执行访问返回resp
HttpResponse resp=hc.execute(httppost);
//获取访问的结果
HttpEntity entity=resp.getEntity();
//把返回的结果转成字符串
jsonStr = EntityUtils.toString(entity);
// DefaultHttpClient hc=new DefaultHttpClient();
// while(true) {
// try {
// //实例化post方式访问并且把路径放入
// HttpPost httppost=new HttpPost(api);
// httppost.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36 Edg/80.0.361.48");
// //把需要的参数传入
// //执行访问返回resp
// HttpResponse resp=hc.execute(httppost);
// //获取访问的结果
// HttpEntity entity=resp.getEntity();
// //把返回的结果转成字符串
// if(isJsonOK()) {
// jsonStr = EntityUtils.toString(entity);
// break;
// }else {
// System.out.println("错误代码:10000");
// continue;
// }
//
// } catch (Exception e) {
// // TODO: handle exception
// e.printStackTrace();
// }//运行完后执行
// finally {
// hc.getConnectionManager().shutdown();
// }

} catch (Exception e) {
// TODO: handle exception
// URL url = null;
// InputStream is = null;
// try {
// url = new URL(api);
// is = url.openStream();
// BufferedReader br = new BufferedReader(new InputStreamReader(is,"ASCII"));
// String msg = null;
// while((msg = br.readLine())!=null) {
// jsonStr += msg;
// }
// System.out.println(msg);
// }catch(Exception e) {
// e.printStackTrace();
// }
URL url = null;
HttpURLConnection conn = null;
InputStream is = null;
BufferedReader br = null;

try {

url = new URL(api);
while(true) {
conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("User-Agent",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64)"
+ " AppleWebKit/537.36 (KHTML, like Gecko) "
+ "Chrome/80.0.3987.87 Safari/537.36 Edg/80.0.361.48");
is = conn.getInputStream();
br = new BufferedReader(new InputStreamReader(is,"ASCII"));
int msg = 0;
jsonStr = "";
while((msg = br.read())!=-1) {
jsonStr += (char)msg;
}
if(jsonStr.contains("\"errcode\":100")) {
//System.out.println("开始"+jsonStr+"结束");
continue;
}else {
//System.out.println("开始"+jsonStr+"结束");
break;
}
}
}catch(Exception e) {
e.printStackTrace();
}finally {
if(br!=null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}//运行完后执行
finally {
hc.getConnectionManager().shutdown();
}

}
}
}

@Override
Expand Down
23 changes: 15 additions & 8 deletions src/cn/mcplugin/kqjcq/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class Main extends JcqAppAbstract implements ICQVer, IMsg, IRequest {
static long time3 = 0L;
static long time4 = 0L;
static long time5 = 0L;
static long time6 = 0L;
static WHComeOn wh = new WHComeOn();
public static void main(String[] args) {
CQ = new CQDebug();
Expand All @@ -31,10 +32,12 @@ public static void main(String[] args) {
@Override
public int startup() {
new Thread(new SickWebSite()).start();
new Thread(new SickWebSite()).start();
new Thread(new JsonInfo()).start();

try {
SickWebSite.getHtmlPageResponse(SickWebSite.qurak);
//SickWebSite.getHtmlPageResponse(SickWebSite.qurak);
SickWebSite.getHtmlPageResponse(SickWebSite.zhihu);
JsonInfo.getDocument();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
Expand Down Expand Up @@ -83,10 +86,11 @@ public int groupMsg(int subType, int msgId, long fromGroup, long fromQQ, String
|| msg.contains("武汉") || msg.contains("病毒")
|| msg.contains("感染")
|| msg.contains("疫情") || msg.contains("瘟疫"))) {
if(SickWebSite.qurakHtml == null || JsonInfo.jsonStr == null) {
if(JsonInfo.jsonStr == null || SickWebSite.zhihuHtml == null) {
try {
SickWebSite.getHtmlPageResponse(SickWebSite.qurak);
//SickWebSite.getHtmlPageResponse(SickWebSite.qurak);
JsonInfo.getDocument();
SickWebSite.getHtmlPageResponse(SickWebSite.zhihu);
} catch (IOException e) {
e.printStackTrace();
}
Expand All @@ -95,9 +99,11 @@ public int groupMsg(int subType, int msgId, long fromGroup, long fromQQ, String
try {
time = System.currentTimeMillis();
//CQ.sendGroupMsg(fromGroup, "正在为您下载地图..."+"\n"+"这可能需要几秒钟的时间"+"\n"+"请耐心等待\n"+"输入 武汉加油 可以为武汉点赞哦!");
CQImage c = new CQImage(SickWebSite.getImageUrl());
File f = new File("C:\\Users\\Administrator\\Desktop\\image\\map.jpg");
c.download(f);
if(time6 == 0L || System.currentTimeMillis() - time6 >= 1000*600) {
CQImage c = new CQImage(SickWebSite.getImageUrl());
c.download(f);
}
CQ.sendGroupMsg(fromGroup, JsonInfo.getGlobalInfo()+CC.image(f));
} catch (IOException e) {
// TODO 自动生成的 catch 块
Expand Down Expand Up @@ -147,7 +153,7 @@ public int groupMsg(int subType, int msgId, long fromGroup, long fromQQ, String

}else if(msg.contains("疫情") && !(msg.contains("地图") || msg.contains("全国"))) {
String[] arr = msg.split("疫情");
if(SickWebSite.qurakHtml == null || JsonInfo.jsonStr == null)
if(JsonInfo.jsonStr == null || SickWebSite.zhihuHtml == null)
CQ.sendGroupMsg(fromGroup,"疫情信息初始化\n"+"这可能需要几秒钟的时间 \n"+"请您耐心等待\n"+"输入 武汉加油 可以为武汉点赞哦!");
CQ.sendGroupMsg(fromGroup,CC.at(fromQQ)+SickWebSite.getArea(arr[0]));
// TODO 自动生成的 catch 块
Expand All @@ -159,7 +165,8 @@ public int groupMsg(int subType, int msgId, long fromGroup, long fromQQ, String
}
try {
CQ.sendGroupMsg(fromGroup,CC.at(fromQQ)+"正在更新中!请稍后"+"输入 武汉加油 为武汉点赞吧!");
SickWebSite.getHtmlPageResponse(SickWebSite.qurak);
//SickWebSite.getHtmlPageResponse(SickWebSite.qurak);
SickWebSite.getHtmlPageResponse(SickWebSite.zhihu);
JsonInfo.getDocument();
} catch (IOException e) {
e.printStackTrace();
Expand Down
Loading

0 comments on commit 3e5ce00

Please sign in to comment.