use of net.sf.json.JSONObject in project pmph by BCSquad.
the class WechatAccessToken method getWXjsTicket.
/**
* <pre>
* 功能描述:获取wx_js_ticket
* 使用示范:
*
* @param accessToken access_token
* @return
* </pre>
*/
public static WXjsTicket getWXjsTicket(String accessToken) {
WXjsTicket wXjsTicket = null;
String requestUrl = WXURLUtil.JSAPIURL.replace("ACCESS_TOKEN", accessToken);
// 发起GET请求获取凭证
JSONObject jsonObject = HttpRequestUtil.httpRequest(requestUrl, "GET", null);
System.out.println("CommonUtil.java 调用了一次getWXjsTicket接口");
if (null != jsonObject) {
try {
wXjsTicket = new WXjsTicket();
wXjsTicket.setJsTicket(jsonObject.getString("ticket"));
wXjsTicket.setJsTicketExpiresIn(jsonObject.getInt("expires_in"));
} catch (JSONException e) {
wXjsTicket = null;
// 获取wXjsTicket失败
log.error("获取wXjsTicket失败 errcode:{} errmsg:{}", jsonObject.getInt("errcode"), jsonObject.getString("errmsg"));
}
}
return wXjsTicket;
}
use of net.sf.json.JSONObject in project topcom-cloud by 545314690.
the class EtlController method commentsEtl.
@ApiOperation("commentsEtl")
@RequestMapping(value = "/commentsEtl", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public Object commentsEtl(@RequestParam Integer limit) {
long count = 0;
long count1 = 0;
SearchResponse searchResponse = scanComments("", limit);
while (searchResponse.getHits().getHits().length > 0) {
SearchHit[] hits = searchResponse.getHits().hits();
List<JSONObject> commentsList = new ArrayList<>();
for (int i = 0; i < hits.length; i++) {
JSONObject jsonObject = JSONObject.fromObject(hits[i].sourceAsMap());
commentsList.add(jsonObject);
}
// String path = "D:\\data\\comments\\"+"comments"+(count1/50000)+".txt";
String path = "/home/yuqing/data/esFile/comments/" + "comments" + (count1 / 50000) + ".txt";
save2File(commentsList, path);
dleteCommentsDoc("yuqing", "comment", commentsList);
count1 = count1 + commentsList.size();
count = count + searchResponse.getHits().getHits().length;
logger.error("删除comments条数:" + count1);
logger.error("处理comments条数:" + count + "\n 完成度" + (double) count * 100 / searchResponse.getHits().getTotalHits() + "%");
searchResponse = scanComments(searchResponse.getScrollId(), limit);
}
return "done";
}
use of net.sf.json.JSONObject in project topcom-cloud by 545314690.
the class EtlController method saveJson.
private void saveJson(String yuqing, String article, List<JSONObject> jsonObjects) {
Client client = elasticsearchTemplate.getClient();
BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
for (int i = 0; i < jsonObjects.size(); i++) {
JSONObject jsonObject = jsonObjects.get(i);
IndexRequestBuilder indexRequestBuilder = client.prepareIndex("yuqing", "article").setSource(jsonObject.toString()).setId(jsonObject.get("id").toString());
bulkRequestBuilder.add(indexRequestBuilder);
}
bulkRequestBuilder.execute().actionGet();
}
use of net.sf.json.JSONObject in project topcom-cloud by 545314690.
the class EtlController method weiboEtl.
/**
* 微博id->weiboId
* md5(id)->微博id
* @param limit
* @return
*/
@ApiOperation("weiboEtl")
@RequestMapping(value = "/weiboEtl", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public Object weiboEtl(@RequestParam Integer limit) {
long count = 0;
SearchResponse searchResponse = scanWeibo("", limit);
while (searchResponse.getHits().getHits().length > 0) {
SearchHit[] hits = searchResponse.getHits().hits();
List<JSONObject> commentsList = new ArrayList<>();
for (int i = 0; i < hits.length; i++) {
JSONObject jsonObject = JSONObject.fromObject(hits[i].sourceAsMap());
jsonObject.put("weiboId", jsonObject.get("id"));
jsonObject.put("id", MD5Utils.md5(jsonObject.get("id").toString()));
commentsList.add(jsonObject);
}
updateJson("yuqing", "article", commentsList);
count = count + searchResponse.getHits().getHits().length;
logger.error(searchResponse.getHits().getTotalHits());
logger.error("处理微博条数:" + count + "\n 完成度" + (double) count * 100 / searchResponse.getHits().getTotalHits() + "%");
searchResponse = scanWeibo(searchResponse.getScrollId(), limit);
}
return "done";
}
use of net.sf.json.JSONObject in project topcom-cloud by 545314690.
the class EtlController method etlSimHash.
public List<JSONObject> etlSimHash(SearchHit[] hits) {
List<JSONObject> commentsList = new ArrayList<>();
for (int i = 0; i < hits.length; i++) {
JSONObject jsonObject = JSONObject.fromObject(hits[i].sourceAsString());
jsonObject.put("textSimHash", SimHasher.analysis(jsonObject.getString("title") + jsonObject.getString("content")).toString());
jsonObject.put("titleSimHash", SimHasher.analysis(jsonObject.getString("title")).toString());
commentsList.add(jsonObject);
}
return commentsList;
}
Aggregations