Commit 7577a1fa by chenweitao

Merge branch 'working' into 'master'

Working

See merge request !203
parents fe68bfbe e4f4c636
package com.zhiwei.searchhotcrawler.bean;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 类型枚举
* @author
* @date
*/
public enum IconEnum {
/** icon图标转换 */
公益("jian_gongyi","益","蓝色","https://simg.s.weibo.com/20211014_jian_gongyi.png"),
推荐("recom_yellow","荐","黄色","https://simg.s.weibo.com/20200925_recom_yellow.png"),
("boom","爆","深红色","https://simg.s.weibo.com/20210226_boom.png"),
("fei","沸","深橙色","https://simg.s.weibo.com/20210226_fei.png"),
("hot","热","橙色","https://simg.s.weibo.com/20210226_hot.png"),
("new","新","红色","https://simg.s.weibo.com/20210226_new.png"),
("jian","商","蓝色","https://simg.s.weibo.com/20210623_jian.png"),
首发("free_issue","首发","蓝色","https://simg.s.weibo.com/20220424_search_ads_%E9%A6%96%E5%8F%91.png"),
预约("appointment","预约","蓝色","https://simg.s.weibo.com/20220424_search_ads_%E9%A2%84%E7%BA%A6.png"),
官宣("Officer_xuan","官宣","蓝色","https://simg.s.weibo.com/20220424_search_ads_%E5%AE%98%E5%AE%A3.png"),
上新("newest","上新","蓝色","https://simg.s.weibo.com/20220424_search_ads_%E4%B8%8A%E6%96%B0.png"),
;
private static Logger logger = LogManager.getLogger(IconEnum.class.getName());
IconEnum(String name, String describe,String color,String iconUrl) {
this.name = name;
this.describe = describe;
this.color = color;
this.iconUrl = iconUrl;
}
/** 图标名 */
private String name;
/** 图标描述 */
private String describe;
/** 图标背景色 */
private String color;
/** 图标地址链接 */
private String iconUrl;
/**
* k name
* v describe
* 根据名获取
**/
static Map<String, String> nameDescribeMap;
static {
nameDescribeMap = Arrays.stream(IconEnum.values()).collect(Collectors.toMap(IconEnum::getName,
IconEnum::getDescribe, (k1, k2) -> k1));
}
/**
* 图标名转换成描述
*
* @param name
* @return
*/
public String nameChangeDescribe(String name) {
if (nameDescribeMap.containsKey(name)) {
return nameDescribeMap.get(name);
} else {
logger.error("未找到相应图标描述,name={}", name);
return null;
}
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescribe() {
return describe;
}
public void setDescribe(String describe) {
this.describe = describe;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String getIconUrl() {
return iconUrl;
}
public void setIconUrl(String iconUrl) {
this.iconUrl = iconUrl;
}
@Override
public String toString() {
return "IconEnum{" +
"name='" + name + '\'' +
", describe='" + describe + '\'' +
", color='" + color + '\'' +
", iconUrl='" + iconUrl + '\'' +
'}';
}
}
......@@ -2,6 +2,7 @@ package com.zhiwei.searchhotcrawler.crawler;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
......@@ -309,7 +310,15 @@ public class WeiboHotSearchCrawler {
String iconUrl = cardInfo.getString("icon");
String icon = null;
if (StringUtils.isNotBlank(iconUrl)) {
icon = iconUrl.split("_")[1].split(".png")[0];
String[] iconString = iconUrl.split("_");
if (iconString.length==4){
icon =iconString[3].split(".png")[0];
icon =URLDecoder.decode(icon, "utf-8");
}else if (iconString.length==3){
icon =iconString[1]+"_"+iconString[2].split(".png")[0];
}else {
icon = iconString[1].split(".png")[0];
}
}
// String id = "http://s.weibo.com/weibo/" + URLCodeUtil.getURLEncode(name, "utf-8") + "&Refer=top";
String id = cardInfo.getString("scheme");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment