Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
searchhotcrawler
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhiwei
searchhotcrawler
Commits
f87165c0
Commit
f87165c0
authored
Sep 29, 2018
by
[zhangzhiwei]
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
推送添加log及重试3次
parent
7fe19a3c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
75 additions
and
48 deletions
+75
-48
src/main/java/com/zhiwei/searchhotcrawler/dao/WeiboHotSearchDAO.java
+1
-1
src/main/java/com/zhiwei/searchhotcrawler/run/HotSearchRun.java
+3
-3
src/main/java/com/zhiwei/searchhotcrawler/timer/SendWeiboHotSearchRun.java
+46
-34
src/main/java/com/zhiwei/searchhotcrawler/timer/SendZhihuHotSearchRun.java
+10
-2
src/main/java/com/zhiwei/searchhotcrawler/util/WechatCodeUtil.java
+15
-8
No files found.
src/main/java/com/zhiwei/searchhotcrawler/dao/WeiboHotSearchDAO.java
View file @
f87165c0
...
...
@@ -87,7 +87,7 @@ public class WeiboHotSearchDAO extends MongoDBTemplate{
Date
date
=
new
Date
((
new
Date
().
getTime
()-
60
*
60
*
1000
));
DBObject
query
=
new
BasicDBObject
();
query
.
put
(
"time"
,
new
BasicDBObject
(
"$gte"
,
date
));
query
.
put
(
"changeCount"
,
0
);
query
.
put
(
"changeCount"
,
0
);
try
{
DBCursor
cur
=
this
.
getReadColl
().
find
(
query
);
...
...
src/main/java/com/zhiwei/searchhotcrawler/run/HotSearchRun.java
View file @
f87165c0
...
...
@@ -25,9 +25,9 @@ public class HotSearchRun {
}
public
static
void
main
(
String
[]
args
)
{
new
HotSearchRun
().
showTimer
();
new
CacheListener
().
startListen
();
//
new SendWeiboHotSearchRun().start();
//
new HotSearchRun().showTimer();
//
new CacheListener().startListen();
new
SendWeiboHotSearchRun
().
start
();
// new SendZhihuHotSearchRun().start();
}
}
src/main/java/com/zhiwei/searchhotcrawler/timer/SendWeiboHotSearchRun.java
View file @
f87165c0
...
...
@@ -16,49 +16,52 @@ import com.zhiwei.searchhotcrawler.util.WechatConstant;
import
com.zhiwei.zhiweiTools.timeParse.TimeParse
;
import
com.zhiwei.zhiweiTools.tools.ZhiWeiTools
;
public
class
SendWeiboHotSearchRun
extends
Thread
{
public
class
SendWeiboHotSearchRun
extends
Thread
{
private
WeiboHotSearchDAO
weiboHotSearchDAO
=
new
WeiboHotSearchDAO
();
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
SendWeiboHotSearchRun
.
class
);
@Override
public
void
run
()
{
while
(
true
)
{
while
(
true
)
{
try
{
Calendar
calendar
=
Calendar
.
getInstance
();
int
hour
=
calendar
.
get
(
Calendar
.
HOUR_OF_DAY
);
logger
.
info
(
"微博推送,当前系统时间为:"
+
hour
);
if
(
hour
>
6
&&
hour
<
23
)
{
if
(
hour
>
6
&&
hour
<
23
)
{
List
<
DBObject
>
list
=
weiboHotSearchDAO
.
getWeiboHotOneHour
();
if
(
list
!=
null
&&
list
.
size
()>
0
)
{
for
(
DBObject
weibo
:
list
)
{
if
(
list
!=
null
&&
list
.
size
()
>
0
)
{
for
(
DBObject
weibo
:
list
)
{
String
title
=
weibo
.
get
(
"name"
).
toString
();
String
time
=
TimeParse
.
dateFormartString
((
Date
)
weibo
.
get
(
"time"
),
"yyyy-MM-dd HH:mm:ss"
);
String
time
=
TimeParse
.
dateFormartString
((
Date
)
weibo
.
get
(
"time"
),
"yyyy-MM-dd HH:mm:ss"
);
String
url
=
weibo
.
get
(
"url"
).
toString
();
sendTemplateByUserIds
(
title
,
time
,
url
);
}
}
else
{
sendTemplateByUserIds
(
"最近一小时无数据"
,
TimeParse
.
dateFormartString
(
new
Date
(),
"yyyy-MM-dd HH:mm:ss"
),
null
);
}
else
{
logger
.
info
(
"微博最近一小时无数据"
);
sendTemplateByUserIds
(
"最近一小时无数据"
,
TimeParse
.
dateFormartString
(
new
Date
(),
"yyyy-MM-dd HH:mm:ss"
),
null
);
}
}
ZhiWeiTools
.
sleep
(
1
*
60
*
60
*
1000
);
ZhiWeiTools
.
sleep
(
1
*
60
*
60
*
1000
);
}
catch
(
Exception
e
)
{
logger
.
debug
(
"微博热搜推送出现问题,问题为:::{}"
,
e
.
fillInStackTrace
());
ZhiWeiTools
.
sleep
(
1
*
60
*
60
*
1000
);
logger
.
debug
(
"微博热搜推送出现问题,问题为:::{}"
,
e
.
fillInStackTrace
());
ZhiWeiTools
.
sleep
(
1
*
60
*
60
*
1000
);
continue
;
}
}
}
/**
* @Title: sendTemplateByUserIds
* @author hero
* @Description: 发送模版消息
* @param @param microTouTiao
* @param @param userList 设定文件
* @Title: sendTemplateByUserIds
* @author hero
* @Description: 发送模版消息
* @param @param
* microTouTiao
* @param @param
* userList 设定文件
* @return void 返回类型
*/
public
static
void
sendTemplateByUserIds
(
String
title
,
String
time
,
String
url
)
{
public
static
void
sendTemplateByUserIds
(
String
title
,
String
time
,
String
url
)
{
Map
<
String
,
Object
>
dataMap
=
new
HashMap
<>();
JSONObject
first
=
new
JSONObject
();
first
.
put
(
"value"
,
"您好,有一条来自微博热搜榜的预警通知。"
);
...
...
@@ -78,35 +81,44 @@ public class SendWeiboHotSearchRun extends Thread{
JSONObject
remark
=
new
JSONObject
();
remark
.
put
(
"value"
,
"知微情报监测服务"
);
dataMap
.
put
(
"remark"
,
remark
);
List
<
String
>
userList
=
getUserList
();
if
(
userList
!=
null
&&
userList
.
size
()>
0
)
{
if
(
userList
!=
null
&&
userList
.
size
()
>
0
)
{
for
(
String
openId
:
userList
)
{
Template
template
=
new
Template
();
template
.
setTouser
(
openId
);
if
(
url
!=
null
)
{
if
(
url
!=
null
)
{
template
.
setUrl
(
url
);
}
template
.
setTemplate_id
(
WechatConstant
.
WECHAT_TEMPLATEID_EARLY_IT
);
template
.
setData
(
dataMap
);
JSONObject
templateJson
=
(
JSONObject
)
JSONObject
.
toJSON
(
template
);
JSONObject
templateJson
=
(
JSONObject
)
JSONObject
.
toJSON
(
template
);
WechatCodeUtil
.
sendDataJson
(
templateJson
);
}
}
else
{
logger
.
info
(
"拉取微博用户列表失败"
);
}
}
/**
* @Title: getUserList
* @author hero
* @Title: getUserList
* @author hero
* @Description: 用户列表
* @param @param projectName
* @param @return 设定文件
* @param @param
* projectName
* @param @return
* 设定文件
* @return List<String> 返回类型
*/
public
static
List
<
String
>
getUserList
()
{
List
<
String
>
userList
=
WechatCodeUtil
.
getUserList
(
"weibohot"
);
return
userList
;
public
static
List
<
String
>
getUserList
()
{
for
(
int
i
=
0
;
i
<
3
;
i
++)
{
List
<
String
>
userList
=
WechatCodeUtil
.
getUserList
(
"weibohot"
);
if
(
userList
!=
null
)
{
return
userList
;
}
else
{
continue
;
}
}
return
null
;
}
}
src/main/java/com/zhiwei/searchhotcrawler/timer/SendZhihuHotSearchRun.java
View file @
f87165c0
...
...
@@ -42,6 +42,7 @@ public class SendZhihuHotSearchRun extends Thread{
}
}
}
else
{
logger
.
info
(
"知乎最近一小时无数据"
);
sendTemplateByUserIds
(
"最近一小时无数据"
,
TimeParse
.
dateFormartString
(
new
Date
(),
"yyyy-MM-dd HH:mm:ss"
),
null
);
}
}
...
...
@@ -115,8 +116,15 @@ public class SendZhihuHotSearchRun extends Thread{
private
static
List
<
String
>
getUserList
()
{
List
<
String
>
userList
=
new
ArrayList
<
String
>();
List
<
String
>
lpUserList
=
WechatCodeUtil
.
getUserList
(
"LP组"
);
userList
.
addAll
(
lpUserList
);
for
(
int
i
=
0
;
i
<
3
;
i
++){
List
<
String
>
lpUserList
=
WechatCodeUtil
.
getUserList
(
"LP组"
);
if
(
lpUserList
!=
null
){
userList
.
addAll
(
lpUserList
);
break
;
}
else
{
continue
;
}
}
return
userList
;
}
...
...
src/main/java/com/zhiwei/searchhotcrawler/util/WechatCodeUtil.java
View file @
f87165c0
...
...
@@ -39,6 +39,7 @@ public class WechatCodeUtil {
}
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
logger
.
error
(
"获取微信公众号推送token失败,问题为:::{}"
,
e
.
fillInStackTrace
());
return
null
;
}
...
...
@@ -87,17 +88,23 @@ public class WechatCodeUtil {
*/
@SuppressWarnings
(
"unchecked"
)
public
static
List
<
String
>
getUserList
(
String
groupName
)
{
String
url
=
"https://api.weixin.qq.com/cgi-bin/user/tag/get?access_token="
+
getToken
();
JSONObject
postData
=
new
JSONObject
();
postData
.
put
(
"tagid"
,
getGroupIp
(
groupName
));
postData
.
put
(
"next_openid"
,
""
);
try
{
JSONObject
jsonObject
=
HttpRequest
.
httpRequest
(
url
,
"GET"
,
postData
.
toString
());
if
(
null
!=
jsonObject
)
{
if
(
jsonObject
.
containsKey
(
"data"
))
{
return
(
List
<
String
>)
jsonObject
.
getJSONObject
(
"data"
).
getObject
(
"openid"
,
List
.
class
);
String
token
=
getToken
();
if
(
token
!=
null
){
String
url
=
"https://api.weixin.qq.com/cgi-bin/user/tag/get?access_token="
+
token
;
JSONObject
postData
=
new
JSONObject
();
postData
.
put
(
"tagid"
,
getGroupIp
(
groupName
));
postData
.
put
(
"next_openid"
,
""
);
JSONObject
jsonObject
=
HttpRequest
.
httpRequest
(
url
,
"GET"
,
postData
.
toString
());
if
(
null
!=
jsonObject
)
{
if
(
jsonObject
.
containsKey
(
"data"
))
{
return
(
List
<
String
>)
jsonObject
.
getJSONObject
(
"data"
).
getObject
(
"openid"
,
List
.
class
);
}
}
}
else
{
logger
.
info
(
"token 获取失败"
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment